diff --git a/python/core/geometry/qgsabstractgeometry.sip b/python/core/geometry/qgsabstractgeometry.sip index 0fa299815ff..55e4fe08c0d 100644 --- a/python/core/geometry/qgsabstractgeometry.sip +++ b/python/core/geometry/qgsabstractgeometry.sip @@ -269,7 +269,7 @@ class QgsAbstractGeometry :rtype: bool %End - virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) = 0; + virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const = 0; %Docstring Returns the vertices adjacent to a specified ``vertex`` within a geometry. .. versionadded:: 3.0 diff --git a/python/core/geometry/qgscurve.sip b/python/core/geometry/qgscurve.sip index 647823ce7a8..f325e79b3a5 100644 --- a/python/core/geometry/qgscurve.sip +++ b/python/core/geometry/qgscurve.sip @@ -102,7 +102,7 @@ class QgsCurve: QgsAbstractGeometry virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const; - virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ); + virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const; virtual int vertexNumberFromVertexId( QgsVertexId id ) const; diff --git a/python/core/geometry/qgscurvepolygon.sip b/python/core/geometry/qgscurvepolygon.sip index 3f1fabcc915..dddd0fe39bb 100644 --- a/python/core/geometry/qgscurvepolygon.sip +++ b/python/core/geometry/qgscurvepolygon.sip @@ -152,7 +152,7 @@ Adds an interior ring to the geometry (takes ownership) virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const; - virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ); + virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const; virtual bool hasCurvedSegments() const; diff --git a/python/core/geometry/qgsgeometry.sip b/python/core/geometry/qgsgeometry.sip index 014370ff1aa..7fada2032ed 100644 --- a/python/core/geometry/qgsgeometry.sip +++ b/python/core/geometry/qgsgeometry.sip @@ -84,19 +84,50 @@ Copy constructor will prompt a deep copy of the object ~QgsGeometry(); - QgsAbstractGeometry *geometry() const; + const QgsAbstractGeometry *constGet() const; %Docstring - Returns the underlying geometry store. -.. versionadded:: 2.10 -.. seealso:: setGeometry + Returns a non-modifiable (const) reference to the underlying abstract geometry primitive. + + This is much faster then calling the non-const get() method. + +.. note:: + + In QGIS 2.x this method was named geometry(). + +.. versionadded:: 3.0 +.. seealso:: primitive() +.. seealso:: set() :rtype: QgsAbstractGeometry %End - void setGeometry( QgsAbstractGeometry *geometry /Transfer/ ); + QgsAbstractGeometry *get(); +%Docstring + Returns a modifiable (non-const) reference to the underlying abstract geometry primitive. + + This method can be slow to call, as it may trigger a detachment of the geometry + and a deep copy. Where possible, use constGet() instead. + +.. note:: + + In QGIS 2.x this method was named geometry(). + +.. versionadded:: 3.0 +.. seealso:: constGet() +.. seealso:: set() + :rtype: QgsAbstractGeometry +%End + + void set( QgsAbstractGeometry *geometry /Transfer/ ); %Docstring Sets the underlying geometry store. Ownership of geometry is transferred. -.. versionadded:: 2.10 -.. seealso:: geometry + +.. note:: + + In QGIS 2.x this method was named setGeometry(). + +.. versionadded:: 3.0 +.. seealso:: get() +.. seealso:: constGet() %End bool isNull() const; diff --git a/python/core/geometry/qgsgeometrycollection.sip b/python/core/geometry/qgsgeometrycollection.sip index b90f2100078..60cc72d7a31 100644 --- a/python/core/geometry/qgsgeometrycollection.sip +++ b/python/core/geometry/qgsgeometrycollection.sip @@ -53,7 +53,7 @@ class QgsGeometryCollection: QgsAbstractGeometry virtual QgsAbstractGeometry *boundary() const /Factory/; - virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ); + virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const; virtual int vertexNumberFromVertexId( QgsVertexId id ) const; diff --git a/python/core/geometry/qgspoint.sip b/python/core/geometry/qgspoint.sip index 70fda7507f8..f67a10c5548 100644 --- a/python/core/geometry/qgspoint.sip +++ b/python/core/geometry/qgspoint.sip @@ -380,7 +380,7 @@ class QgsPoint: QgsAbstractGeometry virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const; - virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ); + virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const; virtual double vertexAngle( QgsVertexId vertex ) const; diff --git a/src/analysis/network/qgsvectorlayerdirector.cpp b/src/analysis/network/qgsvectorlayerdirector.cpp index 3682db89568..e1dd8e254d4 100644 --- a/src/analysis/network/qgsvectorlayerdirector.cpp +++ b/src/analysis/network/qgsvectorlayerdirector.cpp @@ -165,9 +165,9 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const } QgsMultiPolyline mpl; - if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString ) + if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::MultiLineString ) mpl = feature.geometry().asMultiPolyline(); - else if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::LineString ) + else if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::LineString ) mpl.push_back( feature.geometry().asPolyline() ); QgsMultiPolyline::iterator mplIt; @@ -308,9 +308,9 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const // begin features segments and add arc to the Graph; QgsMultiPolyline mpl; - if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString ) + if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::MultiLineString ) mpl = feature.geometry().asMultiPolyline(); - else if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::LineString ) + else if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::LineString ) mpl.push_back( feature.geometry().asPolyline() ); QgsMultiPolyline::iterator mplIt; diff --git a/src/analysis/processing/qgsalgorithmboundary.cpp b/src/analysis/processing/qgsalgorithmboundary.cpp index a5ea9f62c51..3fb46c6a388 100644 --- a/src/analysis/processing/qgsalgorithmboundary.cpp +++ b/src/analysis/processing/qgsalgorithmboundary.cpp @@ -97,7 +97,7 @@ QgsFeature QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsP if ( feature.hasGeometry() ) { QgsGeometry inputGeometry = feature.geometry(); - QgsGeometry outputGeometry = QgsGeometry( inputGeometry.geometry()->boundary() ); + QgsGeometry outputGeometry = QgsGeometry( inputGeometry.constGet()->boundary() ); if ( !outputGeometry ) { feedback->reportError( QObject::tr( "No boundary for feature %1 (possibly a closed linestring?)'" ).arg( feature.id() ) ); diff --git a/src/analysis/processing/qgsalgorithmclip.cpp b/src/analysis/processing/qgsalgorithmclip.cpp index d9f4e988750..0e1766ad647 100644 --- a/src/analysis/processing/qgsalgorithmclip.cpp +++ b/src/analysis/processing/qgsalgorithmclip.cpp @@ -109,7 +109,7 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap ¶meters, Q } // use prepared geometries for faster intersection tests - std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( combinedClipGeom.geometry() ) ); + std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( combinedClipGeom.constGet() ) ); engine->prepareGeometry(); QgsFeatureIds testedFeatureIds; @@ -154,15 +154,15 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap ¶meters, Q } testedFeatureIds.insert( inputFeature.id() ); - if ( !engine->intersects( inputFeature.geometry().geometry() ) ) + if ( !engine->intersects( inputFeature.geometry().constGet() ) ) continue; QgsGeometry newGeometry; - if ( !engine->contains( inputFeature.geometry().geometry() ) ) + if ( !engine->contains( inputFeature.geometry().constGet() ) ) { QgsGeometry currentGeometry = inputFeature.geometry(); newGeometry = combinedClipGeom.intersection( currentGeometry ); - if ( newGeometry.wkbType() == QgsWkbTypes::Unknown || QgsWkbTypes::flatType( newGeometry.geometry()->wkbType() ) == QgsWkbTypes::GeometryCollection ) + if ( newGeometry.wkbType() == QgsWkbTypes::Unknown || QgsWkbTypes::flatType( newGeometry.wkbType() ) == QgsWkbTypes::GeometryCollection ) { QgsGeometry intCom = inputFeature.geometry().combine( newGeometry ); QgsGeometry intSym = inputFeature.geometry().symDifference( newGeometry ); diff --git a/src/analysis/processing/qgsalgorithmconvexhull.cpp b/src/analysis/processing/qgsalgorithmconvexhull.cpp index 405b8983891..382d22dc321 100644 --- a/src/analysis/processing/qgsalgorithmconvexhull.cpp +++ b/src/analysis/processing/qgsalgorithmconvexhull.cpp @@ -76,8 +76,8 @@ QgsFeature QgsConvexHullAlgorithm::processFeature( const QgsFeature &feature, Qg if ( outputGeometry ) { QgsAttributes attrs = f.attributes(); - attrs << outputGeometry.geometry()->area() - << outputGeometry.geometry()->perimeter(); + attrs << outputGeometry.constGet()->area() + << outputGeometry.constGet()->perimeter(); f.setAttributes( attrs ); } } diff --git a/src/analysis/processing/qgsalgorithmdropmzvalues.cpp b/src/analysis/processing/qgsalgorithmdropmzvalues.cpp index 811999a0c49..6075298f516 100644 --- a/src/analysis/processing/qgsalgorithmdropmzvalues.cpp +++ b/src/analysis/processing/qgsalgorithmdropmzvalues.cpp @@ -82,7 +82,7 @@ QgsFeature QgsDropMZValuesAlgorithm::processFeature( const QgsFeature &feature, QgsFeature f = feature; if ( f.hasGeometry() ) { - std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().geometry()->clone() ); + std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().constGet()->clone() ); if ( mDropM ) newGeom->dropMValue(); if ( mDropZ ) diff --git a/src/analysis/processing/qgsalgorithmextractbylocation.cpp b/src/analysis/processing/qgsalgorithmextractbylocation.cpp index c3cd8508f43..419e3e82686 100644 --- a/src/analysis/processing/qgsalgorithmextractbylocation.cpp +++ b/src/analysis/processing/qgsalgorithmextractbylocation.cpp @@ -136,7 +136,7 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource, if ( !engine ) { - engine.reset( QgsGeometry::createGeometryEngine( f.geometry().geometry() ) ); + engine.reset( QgsGeometry::createGeometryEngine( f.geometry().constGet() ) ); engine->prepareGeometry(); } @@ -146,31 +146,31 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource, switch ( predicate ) { case Intersects: - isMatch = engine->intersects( testFeature.geometry().geometry() ); + isMatch = engine->intersects( testFeature.geometry().constGet() ); break; case Contains: - isMatch = engine->contains( testFeature.geometry().geometry() ); + isMatch = engine->contains( testFeature.geometry().constGet() ); break; case Disjoint: - if ( engine->intersects( testFeature.geometry().geometry() ) ) + if ( engine->intersects( testFeature.geometry().constGet() ) ) { disjointSet.remove( testFeature.id() ); } break; case IsEqual: - isMatch = engine->isEqual( testFeature.geometry().geometry() ); + isMatch = engine->isEqual( testFeature.geometry().constGet() ); break; case Touches: - isMatch = engine->touches( testFeature.geometry().geometry() ); + isMatch = engine->touches( testFeature.geometry().constGet() ); break; case Overlaps: - isMatch = engine->overlaps( testFeature.geometry().geometry() ); + isMatch = engine->overlaps( testFeature.geometry().constGet() ); break; case Within: - isMatch = engine->within( testFeature.geometry().geometry() ); + isMatch = engine->within( testFeature.geometry().constGet() ); break; case Crosses: - isMatch = engine->crosses( testFeature.geometry().geometry() ); + isMatch = engine->crosses( testFeature.geometry().constGet() ); break; } if ( isMatch ) diff --git a/src/analysis/processing/qgsalgorithmfixgeometries.cpp b/src/analysis/processing/qgsalgorithmfixgeometries.cpp index 11d5d342bef..290694ab745 100644 --- a/src/analysis/processing/qgsalgorithmfixgeometries.cpp +++ b/src/analysis/processing/qgsalgorithmfixgeometries.cpp @@ -83,7 +83,7 @@ QgsFeature QgsFixGeometriesAlgorithm::processFeature( const QgsFeature &feature, } if ( outputGeometry.wkbType() == QgsWkbTypes::Unknown || - QgsWkbTypes::flatType( outputGeometry.geometry()->wkbType() ) == QgsWkbTypes::GeometryCollection ) + QgsWkbTypes::flatType( outputGeometry.wkbType() ) == QgsWkbTypes::GeometryCollection ) { // keep only the parts of the geometry collection with correct type const QList< QgsGeometry > tmpGeometries = outputGeometry.asGeometryCollection(); diff --git a/src/analysis/processing/qgsalgorithmjoinwithlines.cpp b/src/analysis/processing/qgsalgorithmjoinwithlines.cpp index fbfd74425db..b95abf675a7 100644 --- a/src/analysis/processing/qgsalgorithmjoinwithlines.cpp +++ b/src/analysis/processing/qgsalgorithmjoinwithlines.cpp @@ -177,9 +177,9 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap ¶ { QgsPoint p; if ( feature.geometry().type() == QgsWkbTypes::PointGeometry && !feature.geometry().isMultipart() ) - p = *static_cast< QgsPoint *>( feature.geometry().geometry() ); + p = *static_cast< const QgsPoint *>( feature.geometry().constGet() ); else - p = *static_cast< QgsPoint *>( feature.geometry().pointOnSurface().geometry() ); + p = *static_cast< const QgsPoint *>( feature.geometry().pointOnSurface().constGet() ); if ( hasZ && !p.is3D() ) p.addZValue( 0 ); if ( hasM && !p.isMeasure() ) diff --git a/src/analysis/processing/qgsalgorithmlineintersection.cpp b/src/analysis/processing/qgsalgorithmlineintersection.cpp index 086dc461ad2..ebd61b2b1a0 100644 --- a/src/analysis/processing/qgsalgorithmlineintersection.cpp +++ b/src/analysis/processing/qgsalgorithmlineintersection.cpp @@ -161,7 +161,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p if ( !lines.empty() ) { // use prepared geometries for faster intersection tests - std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( inGeom.geometry() ) ); + std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( inGeom.constGet() ) ); engine->prepareGeometry(); QgsFeatureRequest request = QgsFeatureRequest().setFilterFids( lines ); @@ -178,7 +178,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p } QgsGeometry tmpGeom = inFeatureB.geometry(); - if ( engine->intersects( tmpGeom.geometry() ) ) + if ( engine->intersects( tmpGeom.constGet() ) ) { QgsMultiPoint points; QgsGeometry intersectGeom = inGeom.intersection( tmpGeom ); diff --git a/src/analysis/processing/qgsalgorithmmeancoordinates.cpp b/src/analysis/processing/qgsalgorithmmeancoordinates.cpp index 62cdc539d19..26fb81b6020 100644 --- a/src/analysis/processing/qgsalgorithmmeancoordinates.cpp +++ b/src/analysis/processing/qgsalgorithmmeancoordinates.cpp @@ -164,7 +164,7 @@ QVariantMap QgsMeanCoordinatesAlgorithm::processAlgorithm( const QVariantMap &pa QgsVertexId vid; QgsPoint pt; - const QgsAbstractGeometry *g = feat.geometry().geometry(); + const QgsAbstractGeometry *g = feat.geometry().constGet(); // NOTE - should this be including the duplicate nodes for closed rings? currently it is, // but I suspect that the expected behavior would be to NOT include these while ( g->nextVertex( vid, pt ) ) diff --git a/src/analysis/processing/qgsalgorithmsplitwithlines.cpp b/src/analysis/processing/qgsalgorithmsplitwithlines.cpp index 9510b6fff1c..cbd02163d90 100644 --- a/src/analysis/processing/qgsalgorithmsplitwithlines.cpp +++ b/src/analysis/processing/qgsalgorithmsplitwithlines.cpp @@ -140,11 +140,11 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par QgsGeometry splitGeom = splitGeoms.value( line ); if ( !engine ) { - engine.reset( QgsGeometry::createGeometryEngine( inGeom.geometry() ) ); + engine.reset( QgsGeometry::createGeometryEngine( inGeom.constGet() ) ); engine->prepareGeometry(); } - if ( engine->intersects( splitGeom.geometry() ) ) + if ( engine->intersects( splitGeom.constGet() ) ) { QList< QgsGeometry > splitGeomParts = splitGeom.asGeometryCollection(); splittingLines.append( splitGeomParts ); @@ -159,7 +159,7 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par QList< QgsGeometry > outGeoms; // use prepared geometries for faster intersection tests - std::unique_ptr< QgsGeometryEngine > splitGeomEngine( QgsGeometry::createGeometryEngine( splitGeom.geometry() ) ); + std::unique_ptr< QgsGeometryEngine > splitGeomEngine( QgsGeometry::createGeometryEngine( splitGeom.constGet() ) ); splitGeomEngine->prepareGeometry(); while ( !inGeoms.empty() ) { @@ -172,12 +172,12 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par if ( !inGeom ) continue; - if ( splitGeomEngine->intersects( inGeom.geometry() ) ) + if ( splitGeomEngine->intersects( inGeom.constGet() ) ) { QgsGeometry before = inGeom; if ( splitterPList.empty() ) { - const QgsCoordinateSequence sequence = splitGeom.geometry()->coordinateSequence(); + const QgsCoordinateSequence sequence = splitGeom.constGet()->coordinateSequence(); for ( const QgsRingSequence &part : sequence ) { for ( const QgsPointSequence &ring : part ) @@ -237,12 +237,12 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par bool passed = true; if ( QgsWkbTypes::geometryType( aGeom.wkbType() ) == QgsWkbTypes::LineGeometry ) { - int numPoints = aGeom.geometry()->nCoordinates(); + int numPoints = aGeom.constGet()->nCoordinates(); if ( numPoints <= 2 ) { if ( numPoints == 2 ) - passed = !static_cast< QgsCurve * >( aGeom.geometry() )->isClosed(); // tests if vertex 0 = vertex 1 + passed = !static_cast< const QgsCurve * >( aGeom.constGet() )->isClosed(); // tests if vertex 0 = vertex 1 else passed = false; // sometimes splitting results in lines of zero length } diff --git a/src/analysis/processing/qgsalgorithmtransect.cpp b/src/analysis/processing/qgsalgorithmtransect.cpp index f7a7a59c1ad..a38a57553d5 100644 --- a/src/analysis/processing/qgsalgorithmtransect.cpp +++ b/src/analysis/processing/qgsalgorithmtransect.cpp @@ -132,7 +132,7 @@ QVariantMap QgsTransectAlgorithm::processAlgorithm( const QVariantMap ¶meter QgsGeometry inputGeometry = feat.geometry(); inputGeometry.convertToMultiType(); - const QgsMultiLineString *multiLine = static_cast< QgsMultiLineString * >( inputGeometry.geometry() ); + const QgsMultiLineString *multiLine = static_cast< const QgsMultiLineString * >( inputGeometry.constGet() ); for ( int id = 0; id < multiLine->numGeometries(); ++id ) { const QgsLineString *line = static_cast< const QgsLineString * >( multiLine->geometryN( id ) ); diff --git a/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp b/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp index 9b146151302..cd49b2af87f 100644 --- a/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp +++ b/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp @@ -109,7 +109,7 @@ void QgsFeaturePool::updateFeature( QgsFeature &feature ) get( feature.id(), origFeature ); QgsGeometryMap geometryMap; - geometryMap.insert( feature.id(), QgsGeometry( feature.geometry().geometry()->clone() ) ); + geometryMap.insert( feature.id(), QgsGeometry( feature.geometry().constGet()->clone() ) ); QgsChangedAttributesMap changedAttributesMap; QgsAttributeMap attribMap; for ( int i = 0, n = feature.attributes().size(); i < n; ++i ) diff --git a/src/analysis/vector/geometry_checker/qgsgeometryanglecheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometryanglecheck.cpp index fe858f3847b..9dc26e50da0 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometryanglecheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometryanglecheck.cpp @@ -73,7 +73,7 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method, return; } QgsGeometry featureGeometry = feature.geometry(); - QgsAbstractGeometry *geometry = featureGeometry.geometry(); + QgsAbstractGeometry *geometry = featureGeometry.get(); QgsVertexId vidx = error->vidx(); // Check if point still exists diff --git a/src/analysis/vector/geometry_checker/qgsgeometryareacheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometryareacheck.cpp index d880c68562e..a7275b756a5 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometryareacheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometryareacheck.cpp @@ -49,7 +49,7 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError *error, int method, c } double layerToMapUnits = featurePool->getLayerToMapUnits(); QgsGeometry g = feature.geometry(); - QgsAbstractGeometry *geom = g.geometry(); + const QgsAbstractGeometry *geom = g.constGet(); QgsVertexId vidx = error->vidx(); // Check if polygon still exists @@ -111,7 +111,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature int mergePartIdx = -1; bool matchFound = false; QgsGeometry featureGeometry = feature.geometry(); - QgsAbstractGeometry *geom = featureGeometry.geometry(); + const QgsAbstractGeometry *geom = featureGeometry.constGet(); // Search for touching neighboring geometries for ( QgsFeatureId testId : featurePool->getIntersects( featureGeometry.boundingBox() ) ) @@ -122,7 +122,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature continue; } QgsGeometry testFeatureGeom = testFeature.geometry(); - QgsAbstractGeometry *testGeom = testFeatureGeom.geometry(); + const QgsAbstractGeometry *testGeom = testFeatureGeom.constGet(); for ( int testPartIdx = 0, nTestParts = testGeom->partCount(); testPartIdx < nTestParts; ++testPartIdx ) { if ( testId == feature.id() && testPartIdx == partIdx ) @@ -141,8 +141,8 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature } else { - if ( dynamic_cast( testGeom ) ) - val = static_cast( testGeom )->geometryN( testPartIdx )->area(); + if ( dynamic_cast( testGeom ) ) + val = static_cast( testGeom )->geometryN( testPartIdx )->area(); else val = testGeom->area(); } @@ -178,7 +178,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature // Merge geometries QgsGeometry mergeFeatureGeom = mergeFeature.geometry(); - QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.geometry(); + const QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.constGet(); QSharedPointer geomEngine = QgsGeometryCheckerUtils::createGeomEngine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), mContext->reducedTolerance ); QgsAbstractGeometry *combinedGeom = geomEngine->combine( QgsGeometryCheckerUtils::getGeomPart( geom, partIdx ), &errMsg ); if ( !combinedGeom || combinedGeom->isEmpty() || !QgsWkbTypes::isSingleType( combinedGeom->wkbType() ) ) diff --git a/src/analysis/vector/geometry_checker/qgsgeometrycheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometrycheck.cpp index c7b2c8bdcf3..5168206be07 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrycheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrycheck.cpp @@ -157,10 +157,9 @@ void QgsGeometryCheck::replaceFeatureGeometryPart( const QString &layerId, QgsFe { QgsFeaturePool *featurePool = mContext->featurePools[layerId]; QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); - if ( dynamic_cast( geom ) ) + QgsAbstractGeometry *geom = featureGeom.get(); + if ( QgsGeometryCollection *geomCollection = dynamic_cast< QgsGeometryCollection *>( geom ) ) { - QgsGeometryCollection *geomCollection = static_cast( geom ); geomCollection->removeGeometry( partIdx ); geomCollection->addGeometry( newPartGeom ); changes[layerId][feature.id()].append( Change( ChangePart, ChangeRemoved, QgsVertexId( partIdx ) ) ); @@ -179,7 +178,7 @@ void QgsGeometryCheck::deleteFeatureGeometryPart( const QString &layerId, QgsFea { QgsFeaturePool *featurePool = mContext->featurePools[layerId]; QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + QgsAbstractGeometry *geom = featureGeom.get(); if ( dynamic_cast( geom ) ) { static_cast( geom )->removeGeometry( partIdx ); @@ -206,7 +205,7 @@ void QgsGeometryCheck::deleteFeatureGeometryRing( const QString &layerId, QgsFea { QgsFeaturePool *featurePool = mContext->featurePools[layerId]; QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *partGeom = QgsGeometryCheckerUtils::getGeomPart( featureGeom.geometry(), partIdx ); + QgsAbstractGeometry *partGeom = QgsGeometryCheckerUtils::getGeomPart( featureGeom.get(), partIdx ); if ( dynamic_cast( partGeom ) ) { // If we delete the exterior ring of a polygon, it makes no sense to keep the interiors diff --git a/src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp b/src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp index a77c2e012db..103338a7f51 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp @@ -31,7 +31,7 @@ namespace QgsGeometryCheckerUtils , mFeature( feature ) , mMapCrs( useMapCrs ) { - mGeometry = feature.geometry().geometry()->clone(); + mGeometry = feature.geometry().constGet()->clone(); if ( useMapCrs && !mFeaturePool->getLayerToMapTransform().isShortCircuited() ) { mGeometry->transform( mFeaturePool->getLayerToMapTransform() ); @@ -124,7 +124,7 @@ namespace QgsGeometryCheckerUtils if ( mParent->mProgressCounter ) mParent->mProgressCounter->fetchAndAddRelaxed( 1 ); QgsFeature feature; - if ( featurePool->get( *mFeatureIt, feature ) && feature.geometry() && feature.geometry().geometry() ) + if ( featurePool->get( *mFeatureIt, feature ) && feature.geometry() && feature.geometry().constGet() ) { delete mCurrentFeature; mCurrentFeature = new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mUseMapCrs ); diff --git a/src/analysis/vector/geometry_checker/qgsgeometrydegeneratepolygoncheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometrydegeneratepolygoncheck.cpp index 0dc60883dc2..7e84ceaee4e 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrydegeneratepolygoncheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrydegeneratepolygoncheck.cpp @@ -47,7 +47,7 @@ void QgsGeometryDegeneratePolygonCheck::fixError( QgsGeometryCheckError *error, return; } QgsGeometry featureGeometry = feature.geometry(); - QgsAbstractGeometry *geom = featureGeometry.geometry(); + const QgsAbstractGeometry *geom = featureGeometry.constGet(); QgsVertexId vidx = error->vidx(); // Check if ring still exists diff --git a/src/analysis/vector/geometry_checker/qgsgeometryduplicatenodescheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometryduplicatenodescheck.cpp index 8b6f8cf23d1..2511ebac38c 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometryduplicatenodescheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometryduplicatenodescheck.cpp @@ -55,7 +55,7 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError *error, int return; } QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + QgsAbstractGeometry *geom = featureGeom.get(); QgsVertexId vidx = error->vidx(); // Check if point still exists diff --git a/src/analysis/vector/geometry_checker/qgsgeometryfollowboundariescheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometryfollowboundariescheck.cpp index 18c411fe777..3a39fcef41f 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometryfollowboundariescheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometryfollowboundariescheck.cpp @@ -74,7 +74,7 @@ void QgsGeometryFollowBoundariesCheck::collectErrors( QList refgeomEngine = QgsGeometryCheckerUtils::createGeomEngine( refGeom, mContext->tolerance ); QScopedPointer reducedRefGeom( refgeomEngine->buffer( -mContext->tolerance, 0 ) ); if ( !( geomEngine->contains( reducedRefGeom.data() ) || geomEngine->disjoint( reducedRefGeom.data() ) ) ) diff --git a/src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp index 66a063d30bc..24f95a80e85 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp @@ -168,7 +168,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError *err, Chan continue; } QgsGeometry featureGeom = testFeature.geometry(); - QgsAbstractGeometry *testGeom = featureGeom.geometry(); + const QgsAbstractGeometry *testGeom = featureGeom.constGet(); for ( int iPart = 0, nParts = testGeom->partCount(); iPart < nParts; ++iPart ) { double len = QgsGeometryCheckerUtils::sharedEdgeLength( errLayerGeom, QgsGeometryCheckerUtils::getGeomPart( testGeom, iPart ), mContext->reducedTolerance ); @@ -194,7 +194,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError *err, Chan QgsAbstractGeometry *errLayerGeom = errGeometry->clone(); errLayerGeom->transform( featurePool->getLayerToMapTransform(), QgsCoordinateTransform::ReverseTransform ); QgsGeometry mergeFeatureGeom = mergeFeature.geometry(); - QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.geometry(); + const QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.constGet(); QSharedPointer geomEngine = QgsGeometryCheckerUtils::createGeomEngine( errLayerGeom, mContext->reducedTolerance ); QgsAbstractGeometry *combinedGeom = geomEngine->combine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), &errMsg ); delete errLayerGeom; diff --git a/src/analysis/vector/geometry_checker/qgsgeometryholecheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometryholecheck.cpp index 4b7338fd173..c4d599ad155 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometryholecheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometryholecheck.cpp @@ -53,7 +53,7 @@ void QgsGeometryHoleCheck::fixError( QgsGeometryCheckError *error, int method, c return; } QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + const QgsAbstractGeometry *geom = featureGeom.constGet(); QgsVertexId vidx = error->vidx(); // Check if ring still exists diff --git a/src/analysis/vector/geometry_checker/qgsgeometrymultipartcheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometrymultipartcheck.cpp index 58f3999b3b2..e1a480f7163 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrymultipartcheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrymultipartcheck.cpp @@ -41,7 +41,7 @@ void QgsGeometryMultipartCheck::fixError( QgsGeometryCheckError *error, int meth return; } QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + const QgsAbstractGeometry *geom = featureGeom.constGet(); // Check if error still applies if ( geom->partCount() > 1 || !QgsWkbTypes::isMultiType( geom->wkbType() ) ) diff --git a/src/analysis/vector/geometry_checker/qgsgeometrysegmentlengthcheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometrysegmentlengthcheck.cpp index 6e1f508bb31..a8ccf8781e9 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrysegmentlengthcheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrysegmentlengthcheck.cpp @@ -65,7 +65,7 @@ void QgsGeometrySegmentLengthCheck::fixError( QgsGeometryCheckError *error, int } QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + const QgsAbstractGeometry *geom = featureGeom.constGet(); QgsVertexId vidx = error->vidx(); // Check if point still exists diff --git a/src/analysis/vector/geometry_checker/qgsgeometryselfintersectioncheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometryselfintersectioncheck.cpp index 9aefcf925cf..e676ec51b8e 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometryselfintersectioncheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometryselfintersectioncheck.cpp @@ -90,7 +90,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i return; } QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + QgsAbstractGeometry *geom = featureGeom.get(); QgsVertexId vidx = error->vidx(); // Check if ring still exists diff --git a/src/analysis/vector/geometry_checker/qgsgeometrytypecheck.cpp b/src/analysis/vector/geometry_checker/qgsgeometrytypecheck.cpp index 33fa23789c2..a03cf0a9f9d 100644 --- a/src/analysis/vector/geometry_checker/qgsgeometrytypecheck.cpp +++ b/src/analysis/vector/geometry_checker/qgsgeometrytypecheck.cpp @@ -48,7 +48,7 @@ void QgsGeometryTypeCheck::fixError( QgsGeometryCheckError *error, int method, c return; } QgsGeometry featureGeom = feature.geometry(); - QgsAbstractGeometry *geom = featureGeom.geometry(); + const QgsAbstractGeometry *geom = featureGeom.constGet(); // Check if error still applies QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom->wkbType() ); diff --git a/src/analysis/vector/qgsgeometrysnapper.cpp b/src/analysis/vector/qgsgeometrysnapper.cpp index 778c8d0af31..7a0b3050140 100644 --- a/src/analysis/vector/qgsgeometrysnapper.cpp +++ b/src/analysis/vector/qgsgeometrysnapper.cpp @@ -505,17 +505,17 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl ( mode == EndPointPreferClosest || mode == EndPointPreferNodes || mode == EndPointToEndPoint ) ) return geometry; - QgsPoint center = qgsgeometry_cast< const QgsPoint * >( geometry.geometry() ) ? *static_cast< const QgsPoint * >( geometry.geometry() ) : - QgsPoint( geometry.geometry()->boundingBox().center() ); + QgsPoint center = qgsgeometry_cast< const QgsPoint * >( geometry.constGet() ) ? *static_cast< const QgsPoint * >( geometry.constGet() ) : + QgsPoint( geometry.constGet()->boundingBox().center() ); QgsSnapIndex refSnapIndex( center, 10 * snapTolerance ); Q_FOREACH ( const QgsGeometry &geom, referenceGeometries ) { - refSnapIndex.addGeometry( geom.geometry() ); + refSnapIndex.addGeometry( geom.constGet() ); } // Snap geometries - QgsAbstractGeometry *subjGeom = geometry.geometry()->clone(); + QgsAbstractGeometry *subjGeom = geometry.constGet()->clone(); QList < QList< QList > > subjPointFlags; // Pass 1: snap vertices of subject geometry to reference vertices @@ -619,16 +619,16 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl // Pass 2: add missing vertices to subject geometry Q_FOREACH ( const QgsGeometry &refGeom, referenceGeometries ) { - for ( int iPart = 0, nParts = refGeom.geometry()->partCount(); iPart < nParts; ++iPart ) + for ( int iPart = 0, nParts = refGeom.constGet()->partCount(); iPart < nParts; ++iPart ) { - for ( int iRing = 0, nRings = refGeom.geometry()->ringCount( iPart ); iRing < nRings; ++iRing ) + for ( int iRing = 0, nRings = refGeom.constGet()->ringCount( iPart ); iRing < nRings; ++iRing ) { - for ( int iVert = 0, nVerts = polyLineSize( refGeom.geometry(), iPart, iRing ); iVert < nVerts; ++iVert ) + for ( int iVert = 0, nVerts = polyLineSize( refGeom.constGet(), iPart, iRing ); iVert < nVerts; ++iVert ) { QgsSnapIndex::PointSnapItem *snapPoint = nullptr; QgsSnapIndex::SegmentSnapItem *snapSegment = nullptr; - QgsPoint point = refGeom.geometry()->vertexAt( QgsVertexId( iPart, iRing, iVert ) ); + QgsPoint point = refGeom.constGet()->vertexAt( QgsVertexId( iPart, iRing, iVert ) ); if ( subjSnapIndex->getSnapItem( point, snapTolerance, &snapPoint, &snapSegment ) ) { // Snap to segment, unless a subject point was already snapped to the reference point diff --git a/src/app/dwg/qgsdwgimporter.cpp b/src/app/dwg/qgsdwgimporter.cpp index 21a848d5c5e..1802050c63d 100644 --- a/src/app/dwg/qgsdwgimporter.cpp +++ b/src/app/dwg/qgsdwgimporter.cpp @@ -2672,7 +2672,7 @@ bool QgsDwgImporter::expandInserts( QString &error ) continue; } - QByteArray wkb = g.geometry()->asWkb(); + QByteArray wkb = g.constGet()->asWkb(); if ( OGR_G_CreateFromWkb( ( unsigned char * ) wkb.constData(), nullptr, &ogrG, wkb.size() ) != OGRERR_NONE ) { QgsDebugMsg( QString( "%1/%2: could not create ogr geometry" ).arg( name ).arg( fid ) ); diff --git a/src/app/nodetool/qgsnodetool.cpp b/src/app/nodetool/qgsnodetool.cpp index 5cc81b3b1dc..09f3dab9552 100644 --- a/src/app/nodetool/qgsnodetool.cpp +++ b/src/app/nodetool/qgsnodetool.cpp @@ -54,12 +54,12 @@ uint qHash( const Vertex &v ) //! Find out whether vertex at the given index is an endpoint (assuming linear geometry) static bool isEndpointAtVertexIndex( const QgsGeometry &geom, int vertexIndex ) { - QgsAbstractGeometry *g = geom.geometry(); - if ( QgsCurve *curve = dynamic_cast( g ) ) + const QgsAbstractGeometry *g = geom.constGet(); + if ( const QgsCurve *curve = qgsgeometry_cast< const QgsCurve *>( g ) ) { return vertexIndex == 0 || vertexIndex == curve->numPoints() - 1; } - else if ( QgsMultiCurve *multiCurve = dynamic_cast( g ) ) + else if ( const QgsMultiCurve *multiCurve = qgsgeometry_cast( g ) ) { for ( int i = 0; i < multiCurve->numGeometries(); ++i ) { @@ -83,17 +83,17 @@ static bool isEndpointAtVertexIndex( const QgsGeometry &geom, int vertexIndex ) //! Return index of vertex adjacent to the given endpoint. Assuming linear geometries. int adjacentVertexIndexToEndpoint( const QgsGeometry &geom, int vertexIndex ) { - QgsAbstractGeometry *g = geom.geometry(); - if ( QgsCurve *curve = dynamic_cast( g ) ) + const QgsAbstractGeometry *g = geom.constGet(); + if ( const QgsCurve *curve = qgsgeometry_cast( g ) ) { return vertexIndex == 0 ? 1 : curve->numPoints() - 2; } - else if ( QgsMultiCurve *multiCurve = dynamic_cast( g ) ) + else if ( const QgsMultiCurve *multiCurve = qgsgeometry_cast( g ) ) { int offset = 0; for ( int i = 0; i < multiCurve->numGeometries(); ++i ) { - QgsCurve *part = qgsgeometry_cast( multiCurve->geometryN( i ) ); + const QgsCurve *part = qgsgeometry_cast( multiCurve->geometryN( i ) ); Q_ASSERT( part ); if ( vertexIndex < part->numPoints() ) return vertexIndex == 0 ? offset + 1 : offset + part->numPoints() - 2; @@ -125,7 +125,7 @@ static QgsGeometry geometryToMultiPoint( const QgsGeometry &geom ) { QgsMultiPointV2 *multiPoint = new QgsMultiPointV2(); QgsGeometry outputGeom( multiPoint ); - QgsAbstractGeometry *g = geom.geometry(); + const QgsAbstractGeometry *g = geom.constGet(); for ( int i = 0; i < g->partCount(); ++i ) for ( int j = 0; j < g->ringCount( i ); ++j ) for ( int k = 0; k < g->vertexCount( i, j ); ++k ) @@ -180,7 +180,7 @@ class MatchCollectingFilter : public QgsPointLocator::MatchFilter QgsGeometry matchGeom = nodetool->cachedGeometry( match.layer(), match.featureId() ); QgsVertexId vid; QgsPoint pt; - while ( matchGeom.geometry()->nextVertex( vid, pt ) ) + while ( matchGeom.constGet()->nextVertex( vid, pt ) ) { int vindex = matchGeom.vertexNrFromVertexId( vid ); if ( pt.x() == match.point().x() && pt.y() == match.point().y() && vindex != match.vertexIndex() ) @@ -435,7 +435,7 @@ void QgsNodeTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e ) while ( fi.nextFeature( f ) ) { QgsGeometry g = f.geometry(); - for ( int i = 0; i < g.geometry()->nCoordinates(); ++i ) + for ( int i = 0; i < g.constGet()->nCoordinates(); ++i ) { QgsPointXY pt = g.vertexAt( i ); if ( layerRect.contains( pt ) ) @@ -828,8 +828,8 @@ void QgsNodeTool::mouseMoveNotDragging( QgsMapMouseEvent *e ) QgsGeometry geom = cachedGeometry( m.layer(), m.featureId() ); mFeatureBandMarkers->setToGeometry( geometryToMultiPoint( geom ), m.layer() ); mFeatureBandMarkers->setVisible( true ); - if ( QgsWkbTypes::isCurvedType( geom.geometry()->wkbType() ) ) - geom = QgsGeometry( geom.geometry()->segmentize() ); + if ( QgsWkbTypes::isCurvedType( geom.wkbType() ) ) + geom = QgsGeometry( geom.constGet()->segmentize() ); mFeatureBand->setToGeometry( geom, m.layer() ); mFeatureBand->setVisible( true ); mFeatureBandLayer = m.layer(); @@ -994,7 +994,7 @@ void QgsNodeTool::deleteNodeEditorSelection() if ( mSelectedFeature->geometry()->type() == QgsWkbTypes::LineGeometry ) { // for lines we don't wrap around vertex selection when deleting nodes from end of line - nextVertexToSelect = std::min( nextVertexToSelect, mSelectedFeature->geometry()->geometry()->nCoordinates() - 1 ); + nextVertexToSelect = std::min( nextVertexToSelect, mSelectedFeature->geometry()->constGet()->nCoordinates() - 1 ); } _safeSelectVertex( *mSelectedFeature, nextVertexToSelect ); @@ -1398,7 +1398,7 @@ void QgsNodeTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocator: return; } - QgsAbstractGeometry *geomTmp = geom.geometry()->clone(); + QgsAbstractGeometry *geomTmp = geom.constGet()->clone(); // add/move vertex if ( addingVertex ) @@ -1425,7 +1425,7 @@ void QgsNodeTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocator: } } - geom.setGeometry( geomTmp ); + geom.set( geomTmp ); NodeEdits edits; // dict { layer : { fid : geom } } edits[dragLayer][dragFid] = geom; @@ -1582,7 +1582,7 @@ void QgsNodeTool::deleteVertex() QgsVertexId vid; if ( geom.vertexIdFromVertexNr( vertexIds[i], vid ) ) { - int ringVertexCount = geom.geometry()->vertexCount( vid.part, vid.ring ); + int ringVertexCount = geom.constGet()->vertexCount( vid.part, vid.ring ); if ( vid.vertex == ringVertexCount - 1 ) { // this is the last vertex of the ring - remove the first vertex from the list diff --git a/src/app/nodetool/qgsselectedfeature.cpp b/src/app/nodetool/qgsselectedfeature.cpp index 29801222ca2..50467552b33 100644 --- a/src/app/nodetool/qgsselectedfeature.cpp +++ b/src/app/nodetool/qgsselectedfeature.cpp @@ -274,7 +274,7 @@ void QgsSelectedFeature::createVertexMap() return; } - const QgsAbstractGeometry *geom = mGeometry->geometry(); + const QgsAbstractGeometry *geom = mGeometry->constGet(); if ( !geom ) { return; diff --git a/src/app/qgsmaptooladdpart.cpp b/src/app/qgsmaptooladdpart.cpp index 9fe9b30c0b6..28e536b5b06 100644 --- a/src/app/qgsmaptooladdpart.cpp +++ b/src/app/qgsmaptooladdpart.cpp @@ -154,7 +154,7 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent *e ) QgsGeometry *geom = new QgsGeometry( cp ); geom->avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() ); - const QgsCurvePolygon *cpGeom = qgsgeometry_cast( geom->geometry() ); + const QgsCurvePolygon *cpGeom = qgsgeometry_cast( geom->constGet() ); if ( !cpGeom ) { stopCapturing(); diff --git a/src/app/qgsselectbyformdialog.cpp b/src/app/qgsselectbyformdialog.cpp index f2c99ca46a6..3cdb2b58b87 100644 --- a/src/app/qgsselectbyformdialog.cpp +++ b/src/app/qgsselectbyformdialog.cpp @@ -83,7 +83,7 @@ void QgsSelectByFormDialog::zoomToFeatures( const QString &filter ) while ( features.nextFeature( feat ) ) { QgsGeometry geom = feat.geometry(); - if ( geom.isNull() || geom.geometry()->isEmpty() ) + if ( geom.isNull() || geom.constGet()->isEmpty() ) continue; QgsRectangle r = mMapCanvas->mapSettings().layerExtentToOutputExtent( mLayer, geom.boundingBox() ); diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index 906fe714510..565ee6bff73 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -3677,7 +3677,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT if ( !fet->hasGeometry() ) return; - std::unique_ptr geom( fet->geometry().geometry()->clone() ); + std::unique_ptr geom( fet->geometry().constGet()->clone() ); if ( ct.isValid() ) { geom->transform( ct ); diff --git a/src/core/expression/qgsexpression.cpp b/src/core/expression/qgsexpression.cpp index 0e0a7dfdc49..dbb430a5582 100644 --- a/src/core/expression/qgsexpression.cpp +++ b/src/core/expression/qgsexpression.cpp @@ -780,7 +780,7 @@ QString QgsExpression::formatPreviewString( const QVariant &value ) if ( geom.isNull() ) return tr( "<empty geometry>" ); else - return tr( "<geometry: %1>" ).arg( QgsWkbTypes::displayString( geom.geometry()->wkbType() ) ); + return tr( "<geometry: %1>" ).arg( QgsWkbTypes::displayString( geom.constGet()->wkbType() ) ); } else if ( !value.isValid() ) { diff --git a/src/core/expression/qgsexpressionfunction.cpp b/src/core/expression/qgsexpressionfunction.cpp index 97ba905bd45..6843bb3aca4 100644 --- a/src/core/expression/qgsexpressionfunction.cpp +++ b/src/core/expression/qgsexpressionfunction.cpp @@ -1632,7 +1632,7 @@ static QVariant fcnGeomZ( const QVariantList &values, const QgsExpressionContext //if single point, return the point's z coordinate if ( geom.type() == QgsWkbTypes::PointGeometry && !geom.isMultipart() ) { - QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() ); + const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() ); if ( point ) return point->z(); } @@ -1649,7 +1649,7 @@ static QVariant fcnGeomM( const QVariantList &values, const QgsExpressionContext //if single point, return the point's m value if ( geom.type() == QgsWkbTypes::PointGeometry && !geom.isMultipart() ) { - QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() ); + const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() ); if ( point ) return point->m(); } @@ -1674,7 +1674,7 @@ static QVariant fcnPointN( const QVariantList &values, const QgsExpressionContex return QVariant(); } - QgsPoint point = geom.geometry()->vertexAt( vId ); + QgsPoint point = geom.constGet()->vertexAt( vId ); return QVariant::fromValue( QgsGeometry( new QgsPoint( point ) ) ); } @@ -1691,7 +1691,7 @@ static QVariant fcnStartPoint( const QVariantList &values, const QgsExpressionCo return QVariant(); } - QgsPoint point = geom.geometry()->vertexAt( vId ); + QgsPoint point = geom.constGet()->vertexAt( vId ); return QVariant::fromValue( QgsGeometry( new QgsPoint( point ) ) ); } @@ -1703,12 +1703,12 @@ static QVariant fcnEndPoint( const QVariantList &values, const QgsExpressionCont return QVariant(); QgsVertexId vId; - if ( !geom.vertexIdFromVertexNr( geom.geometry()->nCoordinates() - 1, vId ) ) + if ( !geom.vertexIdFromVertexNr( geom.constGet()->nCoordinates() - 1, vId ) ) { return QVariant(); } - QgsPoint point = geom.geometry()->vertexAt( vId ); + QgsPoint point = geom.constGet()->vertexAt( vId ); return QVariant::fromValue( QgsGeometry( new QgsPoint( point ) ) ); } @@ -1727,7 +1727,7 @@ static QVariant fcnNodesToPoints( const QVariantList &values, const QgsExpressio QgsMultiPointV2 *mp = new QgsMultiPointV2(); - const QgsCoordinateSequence sequence = geom.geometry()->coordinateSequence(); + const QgsCoordinateSequence sequence = geom.constGet()->coordinateSequence(); for ( const QgsRingSequence &part : sequence ) { for ( const QgsPointSequence &ring : part ) @@ -1755,7 +1755,7 @@ static QVariant fcnSegmentsToLines( const QVariantList &values, const QgsExpress if ( geom.isNull() ) return QVariant(); - const QList< QgsLineString * > linesToProcess = QgsGeometryUtils::extractLineStrings( geom.geometry() ); + const QList< QgsLineString * > linesToProcess = QgsGeometryUtils::extractLineStrings( geom.constGet() ); //OK, now we have a complete list of segmentized lines from the geometry QgsMultiLineString *ml = new QgsMultiLineString(); @@ -1782,7 +1782,7 @@ static QVariant fcnInteriorRingN( const QVariantList &values, const QgsExpressio if ( geom.isNull() ) return QVariant(); - QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() ); + const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet() ); if ( !curvePolygon ) return QVariant(); @@ -1804,7 +1804,7 @@ static QVariant fcnGeometryN( const QVariantList &values, const QgsExpressionCon if ( geom.isNull() ) return QVariant(); - QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() ); + const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() ); if ( !collection ) return QVariant(); @@ -1826,7 +1826,7 @@ static QVariant fcnBoundary( const QVariantList &values, const QgsExpressionCont if ( geom.isNull() ) return QVariant(); - QgsAbstractGeometry *boundary = geom.geometry()->boundary(); + QgsAbstractGeometry *boundary = geom.constGet()->boundary(); if ( !boundary ) return QVariant(); @@ -1951,7 +1951,7 @@ static QVariant fcnMakeLine( const QVariantList &values, const QgsExpressionCont if ( geom.type() != QgsWkbTypes::PointGeometry || geom.isMultipart() ) continue; - QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() ); + const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() ); if ( !point ) continue; @@ -1974,7 +1974,7 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC return QVariant(); QgsPolygonV2 *polygon = new QgsPolygonV2(); - polygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( outerRing.geometry()->clone() ) ); + polygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( outerRing.constGet()->clone() ) ); for ( int i = 1; i < values.count(); ++i ) { @@ -1985,7 +1985,7 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC if ( ringGeom.type() != QgsWkbTypes::LineGeometry || ringGeom.isMultipart() || ringGeom.isNull() ) continue; - polygon->addInteriorRing( qgsgeometry_cast< QgsCurve * >( ringGeom.geometry()->clone() ) ); + polygon->addInteriorRing( qgsgeometry_cast< QgsCurve * >( ringGeom.constGet()->clone() ) ); } return QVariant::fromValue( QgsGeometry( polygon ) ); @@ -2006,7 +2006,7 @@ static QVariant fcnMakeTriangle( const QVariantList &values, const QgsExpression if ( geom.type() != QgsWkbTypes::PointGeometry || geom.isMultipart() ) return QVariant(); - QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() ); + const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() ); if ( !point ) return QVariant(); @@ -2035,7 +2035,7 @@ static QVariant fcnMakeCircle( const QVariantList &values, const QgsExpressionCo parent->setEvalErrorString( QObject::tr( "Segment must be greater than 2" ) ); return QVariant(); } - QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() ); + const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() ); QgsCircle circ( *point, radius ); return QVariant::fromValue( QgsGeometry( circ.toPolygon( segment ) ) ); } @@ -2058,7 +2058,7 @@ static QVariant fcnMakeEllipse( const QVariantList &values, const QgsExpressionC parent->setEvalErrorString( QObject::tr( "Segment must be greater than 2" ) ); return QVariant(); } - QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() ); + const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() ); QgsEllipse elp( *point, majorAxis, minorAxis, azimuth ); return QVariant::fromValue( QgsGeometry( elp.toPolygon( segment ) ) ); } @@ -2093,8 +2093,8 @@ static QVariant fcnMakeRegularPolygon( const QVariantList &values, const QgsExpr parent->setEvalErrorString( QObject::tr( "Option can be 0 (inscribed) or 1 (circumscribed)" ) ); return QVariant(); } - QgsPoint *center = qgsgeometry_cast< QgsPoint * >( pt1.geometry() ); - QgsPoint *corner = qgsgeometry_cast< QgsPoint * >( pt2.geometry() ); + const QgsPoint *center = qgsgeometry_cast< const QgsPoint * >( pt1.constGet() ); + const QgsPoint *corner = qgsgeometry_cast< const QgsPoint * >( pt2.constGet() ); QgsRegularPolygon rp = QgsRegularPolygon( *center, *corner, nbEdges, option ); @@ -2112,9 +2112,9 @@ static QVariant pointAt( const QVariantList &values, const QgsExpressionContext if ( idx < 0 ) { - idx += g.geometry()->nCoordinates(); + idx += g.constGet()->nCoordinates(); } - if ( idx < 0 || idx >= g.geometry()->nCoordinates() ) + if ( idx < 0 || idx >= g.constGet()->nCoordinates() ) { parent->setEvalErrorString( QObject::tr( "Index is out of range" ) ); return QVariant(); @@ -2221,7 +2221,7 @@ static QVariant fcnGeomPerimeter( const QVariantList &, const QgsExpressionConte } else { - return f.geometry().isNull() ? QVariant( 0 ) : QVariant( f.geometry().geometry()->perimeter() ); + return f.geometry().isNull() ? QVariant( 0 ) : QVariant( f.geometry().constGet()->perimeter() ); } } @@ -2239,7 +2239,7 @@ static QVariant fcnPerimeter( const QVariantList &values, const QgsExpressionCon static QVariant fcnGeomNumPoints( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * ) { QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent ); - return QVariant( geom.isNull() ? 0 : geom.geometry()->nCoordinates() ); + return QVariant( geom.isNull() ? 0 : geom.constGet()->nCoordinates() ); } static QVariant fcnGeomNumGeometries( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * ) @@ -2248,7 +2248,7 @@ static QVariant fcnGeomNumGeometries( const QVariantList &values, const QgsExpre if ( geom.isNull() ) return QVariant(); - return QVariant( geom.geometry()->partCount() ); + return QVariant( geom.constGet()->partCount() ); } static QVariant fcnGeomNumInteriorRings( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * ) @@ -2258,17 +2258,17 @@ static QVariant fcnGeomNumInteriorRings( const QVariantList &values, const QgsEx if ( geom.isNull() ) return QVariant(); - QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() ); + const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet() ); if ( curvePolygon ) return QVariant( curvePolygon->numInteriorRings() ); - QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() ); + const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() ); if ( collection ) { //find first CurvePolygon in collection for ( int i = 0; i < collection->numGeometries(); ++i ) { - curvePolygon = qgsgeometry_cast< QgsCurvePolygon *>( collection->geometryN( i ) ); + curvePolygon = qgsgeometry_cast< const QgsCurvePolygon *>( collection->geometryN( i ) ); if ( !curvePolygon ) continue; @@ -2286,13 +2286,13 @@ static QVariant fcnGeomNumRings( const QVariantList &values, const QgsExpression if ( geom.isNull() ) return QVariant(); - QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() ); + const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet() ); if ( curvePolygon ) return QVariant( curvePolygon->ringCount() ); bool foundPoly = false; int ringCount = 0; - QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() ); + const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() ); if ( collection ) { //find CurvePolygons in collection @@ -2363,7 +2363,7 @@ static QVariant fcnIsClosed( const QVariantList &values, const QgsExpressionCont if ( fGeom.isNull() ) return QVariant(); - QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( fGeom.geometry() ); + const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( fGeom.constGet() ); if ( !curve ) return QVariant(); @@ -2381,19 +2381,19 @@ static QVariant fcnRelate( const QVariantList &values, const QgsExpressionContex if ( fGeom.isNull() || sGeom.isNull() ) return QVariant(); - std::unique_ptr engine( QgsGeometry::createGeometryEngine( fGeom.geometry() ) ); + std::unique_ptr engine( QgsGeometry::createGeometryEngine( fGeom.constGet() ) ); if ( values.length() == 2 ) { //two geometry arguments, return relation - QString result = engine->relate( sGeom.geometry() ); + QString result = engine->relate( sGeom.constGet() ); return QVariant::fromValue( result ); } else { //three arguments, test pattern QString pattern = QgsExpressionUtils::getStringValue( values.at( 2 ), parent ); - bool result = engine->relatePattern( sGeom.geometry(), pattern ); + bool result = engine->relatePattern( sGeom.constGet(), pattern ); return QVariant::fromValue( result ); } } @@ -2578,7 +2578,7 @@ static QVariant fcnReverse( const QVariantList &values, const QgsExpressionConte if ( fGeom.isNull() ) return QVariant(); - QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( fGeom.geometry() ); + const QgsCurve *curve = qgsgeometry_cast( fGeom.constGet() ); if ( !curve ) return QVariant(); @@ -2593,7 +2593,7 @@ static QVariant fcnExteriorRing( const QVariantList &values, const QgsExpression if ( fGeom.isNull() ) return QVariant(); - QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( fGeom.geometry() ); + const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( fGeom.constGet() ); if ( !curvePolygon || !curvePolygon->exteriorRing() ) return QVariant(); @@ -2677,8 +2677,8 @@ static QVariant fcnAzimuth( const QVariantList &values, const QgsExpressionConte QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent ); QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent ); - const QgsPoint *pt1 = qgsgeometry_cast( fGeom1.geometry() ); - const QgsPoint *pt2 = qgsgeometry_cast( fGeom2.geometry() ); + const QgsPoint *pt1 = qgsgeometry_cast( fGeom1.constGet() ); + const QgsPoint *pt2 = qgsgeometry_cast( fGeom2.constGet() ); if ( !pt1 || !pt2 ) { @@ -2749,7 +2749,7 @@ static QVariant fcnProject( const QVariantList &values, const QgsExpressionConte double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent ); double inclination = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent ); - const QgsPoint *p = static_cast( geom.geometry() ); + const QgsPoint *p = static_cast( geom.constGet() ); QgsPoint newPoint = p->project( distance, 180.0 * azimuth / M_PI, 180.0 * inclination / M_PI ); return QVariant::fromValue( QgsGeometry( new QgsPoint( newPoint ) ) ); @@ -2760,8 +2760,8 @@ static QVariant fcnInclination( const QVariantList &values, const QgsExpressionC QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent ); QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent ); - const QgsPoint *pt1 = qgsgeometry_cast( fGeom1.geometry() ); - const QgsPoint *pt2 = qgsgeometry_cast( fGeom2.geometry() ); + const QgsPoint *pt1 = qgsgeometry_cast( fGeom1.constGet() ); + const QgsPoint *pt2 = qgsgeometry_cast( fGeom2.constGet() ); if ( ( fGeom1.type() != QgsWkbTypes::PointGeometry ) || ( fGeom2.type() != QgsWkbTypes::PointGeometry ) || !pt1 || !pt2 ) @@ -2785,7 +2785,7 @@ static QVariant fcnExtrude( const QVariantList &values, const QgsExpressionConte QgsGeometry geom = fGeom.extrude( x, y ); - QVariant result = geom.geometry() ? QVariant::fromValue( geom ) : QVariant(); + QVariant result = geom.constGet() ? QVariant::fromValue( geom ) : QVariant(); return result; } @@ -2829,7 +2829,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo unconstedContext = new QgsExpressionContext(); } - QgsGeometryCollection *collection = qgsgeometry_cast( fGeom.geometry() ); + const QgsGeometryCollection *collection = qgsgeometry_cast( fGeom.constGet() ); Q_ASSERT( collection ); // Should have failed the multipart check above QgsFeatureRequest::OrderBy orderBy; @@ -2846,7 +2846,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo sorter.sortFeatures( partFeatures, unconstedContext ); - QgsGeometryCollection *orderedGeom = qgsgeometry_cast( fGeom.geometry()->clone() ); + QgsGeometryCollection *orderedGeom = qgsgeometry_cast( fGeom.constGet()->clone() ); Q_ASSERT( orderedGeom ); @@ -2855,7 +2855,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo for ( const QgsFeature &feature : qgis::as_const( partFeatures ) ) { - orderedGeom->addGeometry( feature.geometry().geometry()->clone() ); + orderedGeom->addGeometry( feature.geometry().constGet()->clone() ); } QVariant result = QVariant::fromValue( QgsGeometry( orderedGeom ) ); diff --git a/src/core/geometry/qgsabstractgeometry.h b/src/core/geometry/qgsabstractgeometry.h index bb3c937c736..736ccaff21c 100644 --- a/src/core/geometry/qgsabstractgeometry.h +++ b/src/core/geometry/qgsabstractgeometry.h @@ -298,7 +298,7 @@ class CORE_EXPORT QgsAbstractGeometry * Returns the vertices adjacent to a specified \a vertex within a geometry. * \since QGIS 3.0 */ - virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) = 0; + virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const = 0; /** * Retrieves the sequence of geometries, rings and nodes. diff --git a/src/core/geometry/qgscurve.cpp b/src/core/geometry/qgscurve.cpp index fae2d4a45ec..30b41816cee 100644 --- a/src/core/geometry/qgscurve.cpp +++ b/src/core/geometry/qgscurve.cpp @@ -78,7 +78,7 @@ bool QgsCurve::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const return pointAt( id.vertex, vertex, id.type ); } -void QgsCurve::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) +void QgsCurve::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const { int n = numPoints(); if ( vertex.vertex < 0 || vertex.vertex >= n ) diff --git a/src/core/geometry/qgscurve.h b/src/core/geometry/qgscurve.h index 556fc7cb8fe..c258001dec1 100644 --- a/src/core/geometry/qgscurve.h +++ b/src/core/geometry/qgscurve.h @@ -103,7 +103,7 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry QgsCoordinateSequence coordinateSequence() const override; bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override; - void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override; + void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; int vertexNumberFromVertexId( QgsVertexId id ) const override; /** diff --git a/src/core/geometry/qgscurvepolygon.cpp b/src/core/geometry/qgscurvepolygon.cpp index 245c46c101f..d46b5bd4a17 100644 --- a/src/core/geometry/qgscurvepolygon.cpp +++ b/src/core/geometry/qgscurvepolygon.cpp @@ -844,7 +844,7 @@ void ringAdjacentVertices( const QgsCurve *curve, QgsVertexId vertex, QgsVertexI } } -void QgsCurvePolygon::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) +void QgsCurvePolygon::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const { if ( !mExteriorRing || vertex.ring < 0 || vertex.ring >= 1 + mInteriorRings.size() ) { diff --git a/src/core/geometry/qgscurvepolygon.h b/src/core/geometry/qgscurvepolygon.h index 6465dc53412..873261e8563 100644 --- a/src/core/geometry/qgscurvepolygon.h +++ b/src/core/geometry/qgscurvepolygon.h @@ -123,7 +123,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override; - void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override; + void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; bool hasCurvedSegments() const override; /** diff --git a/src/core/geometry/qgsgeometry.cpp b/src/core/geometry/qgsgeometry.cpp index 9bf910934eb..cc180a02ea6 100644 --- a/src/core/geometry/qgsgeometry.cpp +++ b/src/core/geometry/qgsgeometry.cpp @@ -120,12 +120,18 @@ void QgsGeometry::reset( std::unique_ptr newGeometry ) d->geometry = std::move( newGeometry ); } -QgsAbstractGeometry *QgsGeometry::geometry() const +const QgsAbstractGeometry *QgsGeometry::constGet() const { return d->geometry.get(); } -void QgsGeometry::setGeometry( QgsAbstractGeometry *geometry ) +QgsAbstractGeometry *QgsGeometry::get() +{ + detach(); + return d->geometry.get(); +} + +void QgsGeometry::set( QgsAbstractGeometry *geometry ) { if ( d->geometry.get() == geometry ) { @@ -872,7 +878,7 @@ int QgsGeometry::makeDifferenceInPlace( const QgsGeometry &other ) QgsGeos geos( d->geometry.get() ); mLastError.clear(); - std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.geometry(), &mLastError ) ); + std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.constGet(), &mLastError ) ); if ( !diffGeom ) { return 1; @@ -892,7 +898,7 @@ QgsGeometry QgsGeometry::makeDifference( const QgsGeometry &other ) const QgsGeos geos( d->geometry.get() ); mLastError.clear(); - std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.geometry(), &mLastError ) ); + std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.constGet(), &mLastError ) ); if ( !diffGeom ) { QgsGeometry result; @@ -932,10 +938,10 @@ QgsGeometry QgsGeometry::orientedMinimumBoundingBox( double &area, double &angle QgsPoint pt1; QgsPoint pt2; // get first point - hull.geometry()->nextVertex( vertexId, pt0 ); + hull.constGet()->nextVertex( vertexId, pt0 ); pt1 = pt0; double prevAngle = 0.0; - while ( hull.geometry()->nextVertex( vertexId, pt2 ) ) + while ( hull.constGet()->nextVertex( vertexId, pt2 ) ) { double currentAngle = QgsGeometryUtils::lineAngle( pt1.x(), pt1.y(), pt2.x(), pt2.y() ); double rotateAngle = 180.0 / M_PI * ( currentAngle - prevAngle ); @@ -945,9 +951,9 @@ QgsGeometry QgsGeometry::orientedMinimumBoundingBox( double &area, double &angle t.rotate( rotateAngle ); t.translate( -pt0.x(), -pt0.y() ); - hull.geometry()->transform( t ); + hull.get()->transform( t ); - QgsRectangle bounds = hull.geometry()->boundingBox(); + QgsRectangle bounds = hull.constGet()->boundingBox(); double currentArea = bounds.width() * bounds.height(); if ( currentArea < area ) { @@ -1047,7 +1053,7 @@ QgsGeometry QgsGeometry::minimalEnclosingCircle( QgsPointXY ¢er, double &rad center = QgsPointXY( circ.center() ); radius = circ.radius(); QgsGeometry geom; - geom.setGeometry( circ.toPolygon( segments ) ); + geom.set( circ.toPolygon( segments ) ); return geom; } @@ -1816,7 +1822,7 @@ QgsGeometry QgsGeometry::voronoiDiagram( const QgsGeometry &extent, double toler QgsGeos geos( d->geometry.get() ); mLastError.clear(); - QgsGeometry result = geos.voronoiDiagram( extent.geometry(), tolerance, edgesOnly, &mLastError ); + QgsGeometry result = geos.voronoiDiagram( extent.constGet(), tolerance, edgesOnly, &mLastError ); result.mLastError = mLastError; return result; } @@ -1873,7 +1879,7 @@ QgsGeometry QgsGeometry::interpolate( double distance ) const if ( type() == QgsWkbTypes::PolygonGeometry ) line = QgsGeometry( d->geometry->boundary() ); - QgsGeos geos( line.geometry() ); + QgsGeos geos( line.constGet() ); mLastError.clear(); std::unique_ptr< QgsAbstractGeometry > result( geos.interpolate( distance, &mLastError ) ); if ( !result ) @@ -1918,7 +1924,7 @@ double QgsGeometry::interpolateAngle( double distance ) const QgsVertexId previous; QgsVertexId next; - if ( !QgsGeometryUtils::verticesAtDistance( *segmentized.geometry(), distance, previous, next ) ) + if ( !QgsGeometryUtils::verticesAtDistance( *segmentized.constGet(), distance, previous, next ) ) return 0.0; if ( previous == next ) @@ -1927,33 +1933,33 @@ double QgsGeometry::interpolateAngle( double distance ) const QgsVertexId v2 = previous; QgsVertexId v1; QgsVertexId v3; - segmentized.geometry()->adjacentVertices( v2, v1, v3 ); + segmentized.constGet()->adjacentVertices( v2, v1, v3 ); if ( v1.isValid() && v3.isValid() ) { - QgsPoint p1 = segmentized.geometry()->vertexAt( v1 ); - QgsPoint p2 = segmentized.geometry()->vertexAt( v2 ); - QgsPoint p3 = segmentized.geometry()->vertexAt( v3 ); + QgsPoint p1 = segmentized.constGet()->vertexAt( v1 ); + QgsPoint p2 = segmentized.constGet()->vertexAt( v2 ); + QgsPoint p3 = segmentized.constGet()->vertexAt( v3 ); double angle1 = QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() ); double angle2 = QgsGeometryUtils::lineAngle( p2.x(), p2.y(), p3.x(), p3.y() ); return QgsGeometryUtils::averageAngle( angle1, angle2 ); } else if ( v3.isValid() ) { - QgsPoint p1 = segmentized.geometry()->vertexAt( v2 ); - QgsPoint p2 = segmentized.geometry()->vertexAt( v3 ); + QgsPoint p1 = segmentized.constGet()->vertexAt( v2 ); + QgsPoint p2 = segmentized.constGet()->vertexAt( v3 ); return QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() ); } else { - QgsPoint p1 = segmentized.geometry()->vertexAt( v1 ); - QgsPoint p2 = segmentized.geometry()->vertexAt( v2 ); + QgsPoint p1 = segmentized.constGet()->vertexAt( v1 ); + QgsPoint p2 = segmentized.constGet()->vertexAt( v2 ); return QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() ); } } else { - QgsPoint p1 = segmentized.geometry()->vertexAt( previous ); - QgsPoint p2 = segmentized.geometry()->vertexAt( next ); + QgsPoint p1 = segmentized.constGet()->vertexAt( previous ); + QgsPoint p2 = segmentized.constGet()->vertexAt( next ); return QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() ); } } @@ -2152,7 +2158,7 @@ bool QgsGeometry::deletePart( int partNum ) if ( !isMultipart() && partNum < 1 ) { - setGeometry( nullptr ); + set( nullptr ); return true; } @@ -2250,7 +2256,7 @@ QgsGeometry QgsGeometry::polygonize( const QList &geometryList ) { if ( !( g.isNull() ) ) { - geomV2List.append( g.geometry() ); + geomV2List.append( g.constGet() ); } } @@ -3107,7 +3113,7 @@ QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry ) in >> byteArray; if ( byteArray.isEmpty() ) { - geometry.setGeometry( nullptr ); + geometry.set( nullptr ); return in; } diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index 97f8dddca1c..7eb801f179b 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -164,18 +164,42 @@ class CORE_EXPORT QgsGeometry ~QgsGeometry(); /** - * Returns the underlying geometry store. - * \since QGIS 2.10 - * \see setGeometry + * Returns a non-modifiable (const) reference to the underlying abstract geometry primitive. + * + * This is much faster then calling the non-const get() method. + * + * \note In QGIS 2.x this method was named geometry(). + * + * \since QGIS 3.0 + * \see primitive() + * \see set() */ - QgsAbstractGeometry *geometry() const; + const QgsAbstractGeometry *constGet() const; + + /** + * Returns a modifiable (non-const) reference to the underlying abstract geometry primitive. + * + * This method can be slow to call, as it may trigger a detachment of the geometry + * and a deep copy. Where possible, use constGet() instead. + * + * \note In QGIS 2.x this method was named geometry(). + * + * \since QGIS 3.0 + * \see constGet() + * \see set() + */ + QgsAbstractGeometry *get(); /** * Sets the underlying geometry store. Ownership of geometry is transferred. - * \since QGIS 2.10 - * \see geometry + * + * \note In QGIS 2.x this method was named setGeometry(). + * + * \since QGIS 3.0 + * \see get() + * \see constGet() */ - void setGeometry( QgsAbstractGeometry *geometry SIP_TRANSFER ); + void set( QgsAbstractGeometry *geometry SIP_TRANSFER ); /** * Returns true if the geometry is null (ie, contains no underlying geometry diff --git a/src/core/geometry/qgsgeometrycollection.cpp b/src/core/geometry/qgsgeometrycollection.cpp index 02f27b8680a..7db38d2a380 100644 --- a/src/core/geometry/qgsgeometrycollection.cpp +++ b/src/core/geometry/qgsgeometrycollection.cpp @@ -80,7 +80,7 @@ QgsAbstractGeometry *QgsGeometryCollection::boundary() const return nullptr; } -void QgsGeometryCollection::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) +void QgsGeometryCollection::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const { if ( vertex.part < 0 || vertex.part >= mGeometries.count() ) { diff --git a/src/core/geometry/qgsgeometrycollection.h b/src/core/geometry/qgsgeometrycollection.h index 753b8bc6db7..b7d396fc828 100644 --- a/src/core/geometry/qgsgeometrycollection.h +++ b/src/core/geometry/qgsgeometrycollection.h @@ -65,7 +65,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry QString geometryType() const override; void clear() override; QgsAbstractGeometry *boundary() const override SIP_FACTORY; - void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override; + void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; int vertexNumberFromVertexId( QgsVertexId id ) const override; //! Adds a geometry and takes ownership. Returns true in case of success. diff --git a/src/core/geometry/qgsgeos.cpp b/src/core/geometry/qgsgeos.cpp index 1f65f83241f..3cd55733136 100644 --- a/src/core/geometry/qgsgeos.cpp +++ b/src/core/geometry/qgsgeos.cpp @@ -341,7 +341,7 @@ QgsAbstractGeometry *QgsGeos::combine( const QList &geomList, QStri if ( !g ) continue; - geosGeometries << asGeos( g.geometry(), mPrecision ).release(); + geosGeometries << asGeos( g.constGet(), mPrecision ).release(); } geos::unique_ptr geomUnion; @@ -2043,7 +2043,7 @@ QgsGeometry QgsGeos::closestPoint( const QgsGeometry &other, QString *errorMsg ) return QgsGeometry(); } - geos::unique_ptr otherGeom( asGeos( other.geometry(), mPrecision ) ); + geos::unique_ptr otherGeom( asGeos( other.constGet(), mPrecision ) ); if ( !otherGeom ) { return QgsGeometry(); @@ -2077,7 +2077,7 @@ QgsGeometry QgsGeos::shortestLine( const QgsGeometry &other, QString *errorMsg ) return QgsGeometry(); } - geos::unique_ptr otherGeom( asGeos( other.geometry(), mPrecision ) ); + geos::unique_ptr otherGeom( asGeos( other.constGet(), mPrecision ) ); if ( !otherGeom ) { return QgsGeometry(); diff --git a/src/core/geometry/qgsinternalgeometryengine.cpp b/src/core/geometry/qgsinternalgeometryengine.cpp index 4e2e58fc408..6561c6303bf 100644 --- a/src/core/geometry/qgsinternalgeometryengine.cpp +++ b/src/core/geometry/qgsinternalgeometryengine.cpp @@ -29,7 +29,7 @@ #include QgsInternalGeometryEngine::QgsInternalGeometryEngine( const QgsGeometry &geometry ) - : mGeometry( geometry.geometry() ) + : mGeometry( geometry.constGet() ) { } diff --git a/src/core/geometry/qgspoint.cpp b/src/core/geometry/qgspoint.cpp index bfefc74ea4f..5543a00fb09 100644 --- a/src/core/geometry/qgspoint.cpp +++ b/src/core/geometry/qgspoint.cpp @@ -401,7 +401,7 @@ bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const } } -void QgsPoint::adjacentVertices( QgsVertexId, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) +void QgsPoint::adjacentVertices( QgsVertexId, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const { previousVertex = QgsVertexId(); nextVertex = QgsVertexId(); diff --git a/src/core/geometry/qgspoint.h b/src/core/geometry/qgspoint.h index 16d8f1581f2..b7744a78af6 100644 --- a/src/core/geometry/qgspoint.h +++ b/src/core/geometry/qgspoint.h @@ -415,7 +415,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override; bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override; - void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override; + void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override; /** * Angle undefined. Always returns 0.0 diff --git a/src/core/providers/memory/qgsmemoryfeatureiterator.cpp b/src/core/providers/memory/qgsmemoryfeatureiterator.cpp index 117593e345c..f2083276352 100644 --- a/src/core/providers/memory/qgsmemoryfeatureiterator.cpp +++ b/src/core/providers/memory/qgsmemoryfeatureiterator.cpp @@ -52,7 +52,7 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource *sour if ( !mFilterRect.isNull() && mRequest.flags() & QgsFeatureRequest::ExactIntersect ) { mSelectRectGeom = QgsGeometry::fromRect( mFilterRect ); - mSelectRectEngine.reset( QgsGeometry::createGeometryEngine( mSelectRectGeom.geometry() ) ); + mSelectRectEngine.reset( QgsGeometry::createGeometryEngine( mSelectRectGeom.constGet() ) ); mSelectRectEngine->prepareGeometry(); } @@ -111,7 +111,7 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature &feature ) if ( !mFilterRect.isNull() && mRequest.flags() & QgsFeatureRequest::ExactIntersect ) { // do exact check in case we're doing intersection - if ( mSource->mFeatures.value( *mFeatureIdListIterator ).hasGeometry() && mSelectRectEngine->intersects( mSource->mFeatures.value( *mFeatureIdListIterator ).geometry().geometry() ) ) + if ( mSource->mFeatures.value( *mFeatureIdListIterator ).hasGeometry() && mSelectRectEngine->intersects( mSource->mFeatures.value( *mFeatureIdListIterator ).geometry().constGet() ) ) hasFeature = true; } else @@ -166,7 +166,7 @@ bool QgsMemoryFeatureIterator::nextFeatureTraverseAll( QgsFeature &feature ) if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect ) { // using exact test when checking for intersection - if ( mSelectIterator->hasGeometry() && mSelectRectEngine->intersects( mSelectIterator->geometry().geometry() ) ) + if ( mSelectIterator->hasGeometry() && mSelectRectEngine->intersects( mSelectIterator->geometry().constGet() ) ) hasFeature = true; } else diff --git a/src/core/qgsdistancearea.cpp b/src/core/qgsdistancearea.cpp index 9e4cd4fc512..3887a399759 100644 --- a/src/core/qgsdistancearea.cpp +++ b/src/core/qgsdistancearea.cpp @@ -180,7 +180,7 @@ double QgsDistanceArea::measureArea( const QgsGeometry &geometry ) const if ( geometry.isNull() ) return 0.0; - const QgsAbstractGeometry *geomV2 = geometry.geometry(); + const QgsAbstractGeometry *geomV2 = geometry.constGet(); return measure( geomV2, Area ); } @@ -189,7 +189,7 @@ double QgsDistanceArea::measureLength( const QgsGeometry &geometry ) const if ( geometry.isNull() ) return 0.0; - const QgsAbstractGeometry *geomV2 = geometry.geometry(); + const QgsAbstractGeometry *geomV2 = geometry.constGet(); return measure( geomV2, Length ); } @@ -198,7 +198,7 @@ double QgsDistanceArea::measurePerimeter( const QgsGeometry &geometry ) const if ( geometry.isNull() ) return 0.0; - const QgsAbstractGeometry *geomV2 = geometry.geometry(); + const QgsAbstractGeometry *geomV2 = geometry.constGet(); if ( !geomV2 || geomV2->dimension() < 2 ) { return 0.0; diff --git a/src/core/qgsjsonutils.cpp b/src/core/qgsjsonutils.cpp index 90455276f80..36d59554da9 100644 --- a/src/core/qgsjsonutils.cpp +++ b/src/core/qgsjsonutils.cpp @@ -93,7 +93,7 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian } QgsRectangle box = geom.boundingBox(); - if ( QgsWkbTypes::flatType( geom.geometry()->wkbType() ) != QgsWkbTypes::Point ) + if ( QgsWkbTypes::flatType( geom.wkbType() ) != QgsWkbTypes::Point ) { s += QStringLiteral( " \"bbox\":[%1, %2, %3, %4],\n" ).arg( qgsDoubleToString( box.xMinimum(), mPrecision ), qgsDoubleToString( box.yMinimum(), mPrecision ), diff --git a/src/core/qgsmaphittest.cpp b/src/core/qgsmaphittest.cpp index 6e75c0b55c5..cc4b68d5d69 100644 --- a/src/core/qgsmaphittest.cpp +++ b/src/core/qgsmaphittest.cpp @@ -133,7 +133,7 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, else { request.setFilterRect( transformedPolygon.boundingBox() ); - polygonEngine.reset( QgsGeometry::createGeometryEngine( transformedPolygon.geometry() ) ); + polygonEngine.reset( QgsGeometry::createGeometryEngine( transformedPolygon.constGet() ) ); polygonEngine->prepareGeometry(); } } @@ -155,7 +155,7 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, // filter out elements outside of the polygon if ( f.geometry() && polygonEngine ) { - if ( !polygonEngine->intersects( f.geometry().geometry() ) ) + if ( !polygonEngine->intersects( f.geometry().constGet() ) ) { continue; } diff --git a/src/core/qgsmaptopixelgeometrysimplifier.cpp b/src/core/qgsmaptopixelgeometrysimplifier.cpp index f6f877ba5b0..e4fd2df69c2 100644 --- a/src/core/qgsmaptopixelgeometrysimplifier.cpp +++ b/src/core/qgsmaptopixelgeometrysimplifier.cpp @@ -269,11 +269,11 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry( { const QgsPolygonV2 &srcPolygon = dynamic_cast( geometry ); std::unique_ptr polygon( new QgsPolygonV2() ); - polygon->setExteriorRing( qgsgeometry_cast( simplifyGeometry( simplifyFlags, simplifyAlgorithm, srcPolygon.exteriorRing()->wkbType(), *srcPolygon.exteriorRing(), envelope, map2pixelTol, true ).geometry()->clone() ) ); + polygon->setExteriorRing( qgsgeometry_cast( simplifyGeometry( simplifyFlags, simplifyAlgorithm, srcPolygon.exteriorRing()->wkbType(), *srcPolygon.exteriorRing(), envelope, map2pixelTol, true ).constGet()->clone() ) ); for ( int i = 0; i < srcPolygon.numInteriorRings(); ++i ) { const QgsCurve *sub = srcPolygon.interiorRing( i ); - polygon->addInteriorRing( qgsgeometry_cast( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, true ).geometry()->clone() ) ); + polygon->addInteriorRing( qgsgeometry_cast( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, true ).constGet()->clone() ) ); } return QgsGeometry( polygon.release() ); } @@ -285,7 +285,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry( for ( int i = 0; i < numGeoms; ++i ) { const QgsAbstractGeometry *sub = srcCollection.geometryN( i ); - collection->addGeometry( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, false ).geometry()->clone() ); + collection->addGeometry( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, false ).constGet()->clone() ); } return QgsGeometry( collection.release() ); } @@ -320,7 +320,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplify( const QgsGeometry &geometry ) con } const bool isaLinearRing = flatType == QgsWkbTypes::Polygon; - const int numPoints = geometry.geometry()->nCoordinates(); + const int numPoints = geometry.constGet()->nCoordinates(); if ( numPoints <= ( isaLinearRing ? 6 : 3 ) ) { @@ -335,5 +335,5 @@ QgsGeometry QgsMapToPixelSimplifier::simplify( const QgsGeometry &geometry ) con return geometry; } - return simplifyGeometry( mSimplifyFlags, mSimplifyAlgorithm, geometry.wkbType(), *geometry.geometry(), envelope, mTolerance, false ); + return simplifyGeometry( mSimplifyFlags, mSimplifyAlgorithm, geometry.wkbType(), *geometry.constGet(), envelope, mTolerance, false ); } diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index fc332195fdc..cff1418d906 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -1494,7 +1494,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature &f, QgsRenderContext &cont if ( ( geom.type() == QgsWkbTypes::PolygonGeometry ) && ( placement == Line || placement == PerimeterCurved ) ) { - geom = QgsGeometry( geom.geometry()->boundary() ); + geom = QgsGeometry( geom.constGet()->boundary() ); } GEOSGeometry *geos_geom_clone = nullptr; @@ -1779,8 +1779,8 @@ void QgsPalLayerSettings::registerFeature( QgsFeature &f, QgsRenderContext &cont if ( QgsPalLabeling::geometryRequiresPreparation( ddPoint, context, ct ) ) { ddPoint = QgsPalLabeling::prepareGeometry( ddPoint, context, ct ); - xPos = static_cast< QgsPoint * >( ddPoint.geometry() )->x(); - yPos = static_cast< QgsPoint * >( ddPoint.geometry() )->y(); + xPos = static_cast< const QgsPoint * >( ddPoint.constGet() )->x(); + yPos = static_cast< const QgsPoint * >( ddPoint.constGet() )->y(); } xPos += xdiff; diff --git a/src/core/qgstracer.cpp b/src/core/qgstracer.cpp index d2e871a0776..702699bd630 100644 --- a/src/core/qgstracer.cpp +++ b/src/core/qgstracer.cpp @@ -414,16 +414,16 @@ void extractLinework( const QgsGeometry &g, QgsMultiPolyline &mpl ) QgsGeometry geom = g; // segmentize curved geometries - we will use noding algorithm from GEOS // to find all intersections a bit later (so we need them segmentized anyway) - if ( QgsWkbTypes::isCurvedType( g.geometry()->wkbType() ) ) + if ( QgsWkbTypes::isCurvedType( g.wkbType() ) ) { - QgsAbstractGeometry *segmentizedGeomV2 = g.geometry()->segmentize(); + QgsAbstractGeometry *segmentizedGeomV2 = g.constGet()->segmentize(); if ( !segmentizedGeomV2 ) return; geom = QgsGeometry( segmentizedGeomV2 ); } - switch ( QgsWkbTypes::flatType( geom.geometry()->wkbType() ) ) + switch ( QgsWkbTypes::flatType( geom.wkbType() ) ) { case QgsWkbTypes::LineString: mpl << geom.asPolyline(); diff --git a/src/core/qgsvectordataprovider.cpp b/src/core/qgsvectordataprovider.cpp index a8678f2308f..65e6edf9d76 100644 --- a/src/core/qgsvectordataprovider.cpp +++ b/src/core/qgsvectordataprovider.cpp @@ -692,7 +692,7 @@ QgsGeometry QgsVectorDataProvider::convertToProviderType( const QgsGeometry &geo return QgsGeometry(); } - QgsAbstractGeometry *geometry = geom.geometry(); + const QgsAbstractGeometry *geometry = geom.constGet(); if ( !geometry ) { return QgsGeometry(); diff --git a/src/core/qgsvectorfilewriter.cpp b/src/core/qgsvectorfilewriter.cpp index a2fac302619..c4330c11f9e 100644 --- a/src/core/qgsvectorfilewriter.cpp +++ b/src/core/qgsvectorfilewriter.cpp @@ -2109,13 +2109,13 @@ OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature &feature ) QgsGeometry geom = feature.geometry(); // turn single geometry to multi geometry if needed - if ( QgsWkbTypes::flatType( geom.geometry()->wkbType() ) != QgsWkbTypes::flatType( mWkbType ) && - QgsWkbTypes::flatType( geom.geometry()->wkbType() ) == QgsWkbTypes::flatType( QgsWkbTypes::singleType( mWkbType ) ) ) + if ( QgsWkbTypes::flatType( geom.wkbType() ) != QgsWkbTypes::flatType( mWkbType ) && + QgsWkbTypes::flatType( geom.wkbType() ) == QgsWkbTypes::flatType( QgsWkbTypes::singleType( mWkbType ) ) ) { geom.convertToMultiType(); } - if ( geom.geometry()->wkbType() != mWkbType ) + if ( geom.wkbType() != mWkbType ) { OGRGeometryH mGeom2 = nullptr; @@ -2127,10 +2127,10 @@ OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature &feature ) //so the exported WKB has a different type to what the OGRGeometry is expecting. //possibly this is handled already in OGR, but it should be fixed regardless by actually converting //geom to the correct WKB type - QgsWkbTypes::Type wkbType = geom.geometry()->wkbType(); + QgsWkbTypes::Type wkbType = geom.wkbType(); if ( wkbType >= QgsWkbTypes::PointZ && wkbType <= QgsWkbTypes::MultiPolygonZ ) { - QgsWkbTypes::Type wkbType25d = static_cast( geom.geometry()->wkbType() - QgsWkbTypes::PointZ + QgsWkbTypes::Point25D ); + QgsWkbTypes::Type wkbType25d = static_cast( geom.wkbType() - QgsWkbTypes::PointZ + QgsWkbTypes::Point25D ); mGeom2 = createEmptyGeometry( wkbType25d ); } } @@ -2145,7 +2145,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature &feature ) // // Btw. OGRGeometry must be exactly of the type of the geometry which it will receive // i.e. Polygons can't be imported to OGRMultiPolygon - mGeom2 = createEmptyGeometry( geom.geometry()->wkbType() ); + mGeom2 = createEmptyGeometry( geom.wkbType() ); } if ( !mGeom2 ) @@ -2431,7 +2431,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer *layer, } } - if ( fet.hasGeometry() && QgsWkbTypes::isMultiType( fet.geometry().geometry()->wkbType() ) ) + if ( fet.hasGeometry() && QgsWkbTypes::isMultiType( fet.geometry().wkbType() ) ) { destWkbType = QgsWkbTypes::multiType( destWkbType ); break; @@ -2526,7 +2526,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer *layer, req.setFilterRect( filterRect ); } filterRectGeometry = QgsGeometry::fromRect( options.filterExtent ); - filterRectEngine.reset( QgsGeometry::createGeometryEngine( filterRectGeometry.geometry() ) ); + filterRectEngine.reset( QgsGeometry::createGeometryEngine( filterRectGeometry.constGet() ) ); filterRectEngine->prepareGeometry(); } @@ -2613,7 +2613,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer *layer, } } - if ( fet.hasGeometry() && filterRectEngine && !filterRectEngine->intersects( fet.geometry().geometry() ) ) + if ( fet.hasGeometry() && filterRectEngine && !filterRectEngine->intersects( fet.geometry().constGet() ) ) continue; if ( attributes.empty() && options.skipAttributeCreation ) diff --git a/src/core/qgsvectorlayereditutils.cpp b/src/core/qgsvectorlayereditutils.cpp index 7e9d7fca2e7..40845aa2a16 100644 --- a/src/core/qgsvectorlayereditutils.cpp +++ b/src/core/qgsvectorlayereditutils.cpp @@ -105,10 +105,10 @@ QgsVectorLayer::EditResult QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId f if ( !geometry.deleteVertex( vertex ) ) return QgsVectorLayer::EditFailed; - if ( geometry.geometry() && geometry.geometry()->nCoordinates() == 0 ) + if ( geometry.constGet() && geometry.constGet()->nCoordinates() == 0 ) { //last vertex deleted, set geometry to null - geometry.setGeometry( nullptr ); + geometry.set( nullptr ); } mLayer->editBuffer()->changeGeometry( featureId, geometry ); diff --git a/src/core/qgsvectorlayerlabelprovider.cpp b/src/core/qgsvectorlayerlabelprovider.cpp index fde6b9d2b47..f156d466f7d 100644 --- a/src/core/qgsvectorlayerlabelprovider.cpp +++ b/src/core/qgsvectorlayerlabelprovider.cpp @@ -266,16 +266,16 @@ QgsGeometry QgsVectorLayerLabelProvider::getPointObstacleGeometry( QgsFeature &f if ( !fet.hasGeometry() || fet.geometry().type() != QgsWkbTypes::PointGeometry ) return QgsGeometry(); - bool isMultiPoint = fet.geometry().geometry()->nCoordinates() > 1; + bool isMultiPoint = fet.geometry().constGet()->nCoordinates() > 1; QgsAbstractGeometry *obstacleGeom = nullptr; if ( isMultiPoint ) obstacleGeom = new QgsMultiPolygonV2(); // for each point - for ( int i = 0; i < fet.geometry().geometry()->nCoordinates(); ++i ) + for ( int i = 0; i < fet.geometry().constGet()->nCoordinates(); ++i ) { QRectF bounds; - QgsPoint p = fet.geometry().geometry()->vertexAt( QgsVertexId( i, 0, 0 ) ); + QgsPoint p = fet.geometry().constGet()->vertexAt( QgsVertexId( i, 0, 0 ) ); double x = p.x(); double y = p.y(); double z = 0; // dummy variable for coordinate transforms diff --git a/src/core/symbology/qgsfillsymbollayer.cpp b/src/core/symbology/qgsfillsymbollayer.cpp index 1433dd5fc42..5d5caef6b93 100644 --- a/src/core/symbology/qgsfillsymbollayer.cpp +++ b/src/core/symbology/qgsfillsymbollayer.cpp @@ -3415,8 +3415,8 @@ void QgsCentroidFillSymbolLayer::renderPolygon( const QPolygonF &points, QList 1 ) { - QgsGeometry geom = feature->geometry(); - const QgsGeometryCollection *geomCollection = static_cast( geom.geometry() ); + const QgsGeometry geom = feature->geometry(); + const QgsGeometryCollection *geomCollection = static_cast( geom.constGet() ); double area = 0; double areaBiggest = 0; diff --git a/src/core/symbology/qgsinvertedpolygonrenderer.cpp b/src/core/symbology/qgsinvertedpolygonrenderer.cpp index ec094cf6ace..8c8e7b03240 100644 --- a/src/core/symbology/qgsinvertedpolygonrenderer.cpp +++ b/src/core/symbology/qgsinvertedpolygonrenderer.cpp @@ -285,7 +285,7 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext &context ) Q_FOREACH ( const QgsGeometry &geom, cit.geometries ) { QgsMultiPolygon multi; - QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom.geometry()->wkbType() ); + QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom.constGet()->wkbType() ); if ( ( type == QgsWkbTypes::Polygon ) || ( type == QgsWkbTypes::CurvePolygon ) ) { diff --git a/src/core/symbology/qgspointdistancerenderer.cpp b/src/core/symbology/qgspointdistancerenderer.cpp index 23256f99248..59cd25f8c95 100644 --- a/src/core/symbology/qgspointdistancerenderer.cpp +++ b/src/core/symbology/qgspointdistancerenderer.cpp @@ -142,7 +142,7 @@ void QgsPointDistanceRenderer::drawGroup( const ClusteredGroup &group, QgsRender QgsMultiPointV2 *groupMultiPoint = new QgsMultiPointV2(); Q_FOREACH ( const GroupedFeature &f, group ) { - groupMultiPoint->addGeometry( f.feature.geometry().geometry()->clone() ); + groupMultiPoint->addGeometry( f.feature.geometry().constGet()->clone() ); } QgsGeometry groupGeom( groupMultiPoint ); QgsGeometry centroid = groupGeom.centroid(); diff --git a/src/core/symbology/qgssymbol.cpp b/src/core/symbology/qgssymbol.cpp index 6959e0eaf23..1fbba98a886 100644 --- a/src/core/symbology/qgssymbol.cpp +++ b/src/core/symbology/qgssymbol.cpp @@ -674,7 +674,7 @@ class ExpressionContextScopePopper void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker, int currentVertexMarkerType, int currentVertexMarkerSize ) { - QgsGeometry geom = feature.geometry(); + const QgsGeometry geom = feature.geometry(); if ( geom.isNull() ) { return; @@ -682,14 +682,14 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont QgsGeometry segmentizedGeometry = geom; bool usingSegmentizedGeometry = false; - context.setGeometry( geom.geometry() ); + context.setGeometry( geom.constGet() ); bool tileMapRendering = context.testFlag( QgsRenderContext::RenderMapTile ); //convert curve types to normal point/line/polygon ones - if ( QgsWkbTypes::isCurvedType( geom.geometry()->wkbType() ) ) + if ( QgsWkbTypes::isCurvedType( geom.constGet()->wkbType() ) ) { - QgsAbstractGeometry *g = geom.geometry()->segmentize( context.segmentationTolerance(), context.segmentationToleranceType() ); + QgsAbstractGeometry *g = geom.constGet()->segmentize( context.segmentationTolerance(), context.segmentationToleranceType() ); if ( !g ) { return; @@ -698,7 +698,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont usingSegmentizedGeometry = true; } - mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.geometry()->partCount() ); + mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.constGet()->partCount() ); mSymbolRenderContext->setGeometryPartNum( 1 ); ExpressionContextScopePopper scopePopper; @@ -729,7 +729,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont segmentizedGeometry = simplifier.simplify( segmentizedGeometry ); } - switch ( QgsWkbTypes::flatType( segmentizedGeometry.geometry()->wkbType() ) ) + switch ( QgsWkbTypes::flatType( segmentizedGeometry.constGet()->wkbType() ) ) { case QgsWkbTypes::Point: { @@ -739,7 +739,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont break; } - const QgsPoint *point = static_cast< const QgsPoint * >( segmentizedGeometry.geometry() ); + const QgsPoint *point = static_cast< const QgsPoint * >( segmentizedGeometry.constGet() ); const QPointF pt = _getPoint( context, *point ); static_cast( this )->renderPoint( pt, &feature, context, layer, selected ); @@ -764,7 +764,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont QgsDebugMsg( "linestring can be drawn only with line symbol!" ); break; } - const QgsCurve &curve = dynamic_cast( *segmentizedGeometry.geometry() ); + const QgsCurve &curve = dynamic_cast( *segmentizedGeometry.constGet() ); const QPolygonF pts = _getLineString( context, curve, !tileMapRendering && clipFeaturesToExtent() ); static_cast( this )->renderPolyline( pts, &feature, context, layer, selected ); @@ -784,7 +784,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont QgsDebugMsg( "polygon can be drawn only with fill symbol!" ); break; } - const QgsPolygonV2 &polygon = dynamic_cast( *segmentizedGeometry.geometry() ); + const QgsPolygonV2 &polygon = dynamic_cast( *segmentizedGeometry.constGet() ); if ( !polygon.exteriorRing() ) { QgsDebugMsg( "cannot render polygon with no exterior ring" ); @@ -813,7 +813,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont break; } - const QgsMultiPointV2 &mp = static_cast< const QgsMultiPointV2 & >( *segmentizedGeometry.geometry() ); + const QgsMultiPointV2 &mp = static_cast< const QgsMultiPointV2 & >( *segmentizedGeometry.constGet() ); if ( drawVertexMarker && !usingSegmentizedGeometry ) { @@ -846,7 +846,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont break; } - const QgsGeometryCollection &geomCollection = dynamic_cast( *segmentizedGeometry.geometry() ); + const QgsGeometryCollection &geomCollection = dynamic_cast( *segmentizedGeometry.constGet() ); const unsigned int num = geomCollection.numGeometries(); for ( unsigned int i = 0; i < num; ++i ) @@ -886,7 +886,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont QPolygonF pts; QList holes; - const QgsGeometryCollection &geomCollection = dynamic_cast( *segmentizedGeometry.geometry() ); + const QgsGeometryCollection &geomCollection = dynamic_cast( *segmentizedGeometry.constGet() ); const unsigned int num = geomCollection.numGeometries(); // Sort components by approximate area (probably a bit faster than using @@ -939,7 +939,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont } case QgsWkbTypes::GeometryCollection: { - const QgsGeometryCollection &geomCollection = dynamic_cast( *segmentizedGeometry.geometry() ); + const QgsGeometryCollection &geomCollection = dynamic_cast( *segmentizedGeometry.constGet() ); if ( geomCollection.numGeometries() == 0 ) { // skip noise from empty geometry collections from simplification @@ -951,7 +951,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont default: QgsDebugMsg( QString( "feature %1: unsupported wkb type %2/%3 for rendering" ) .arg( feature.id() ) - .arg( QgsWkbTypes::displayString( geom.geometry()->wkbType() ) ) + .arg( QgsWkbTypes::displayString( geom.constGet()->wkbType() ) ) .arg( geom.wkbType(), 0, 16 ) ); } @@ -973,7 +973,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont QgsVertexId vertexId; double x, y, z; QPointF mapPoint; - while ( geom.geometry()->nextVertex( vertexId, vertexPoint ) ) + while ( geom.constGet()->nextVertex( vertexId, vertexPoint ) ) { //transform x = vertexPoint.x(); diff --git a/src/gui/qgsexpressionselectiondialog.cpp b/src/gui/qgsexpressionselectiondialog.cpp index 5ec1b2f7662..0ed1dacbdc3 100644 --- a/src/gui/qgsexpressionselectiondialog.cpp +++ b/src/gui/qgsexpressionselectiondialog.cpp @@ -146,7 +146,7 @@ void QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked() while ( features.nextFeature( feat ) ) { QgsGeometry geom = feat.geometry(); - if ( geom.isNull() || geom.geometry()->isEmpty() ) + if ( geom.isNull() || geom.constGet()->isEmpty() ) continue; QgsRectangle r = mMapCanvas->mapSettings().layerExtentToOutputExtent( mLayer, geom.boundingBox() ); diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 045df60dcbb..0012671a14e 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -1018,7 +1018,7 @@ bool QgsMapCanvas::boundingBoxOfFeatureIds( const QgsFeatureIds &ids, QgsVectorL { errorMsg = tr( "Feature does not have a geometry" ); } - else if ( geom.geometry()->isEmpty() ) + else if ( geom.constGet()->isEmpty() ) { errorMsg = tr( "Feature geometry is empty" ); } diff --git a/src/gui/qgsmaptoolcapture.cpp b/src/gui/qgsmaptoolcapture.cpp index cd9c040ba19..2f463e7a18c 100644 --- a/src/gui/qgsmaptoolcapture.cpp +++ b/src/gui/qgsmaptoolcapture.cpp @@ -419,7 +419,7 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs QgsVertexId vId; if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex(), vId ) ) return 2; - layerPoint = f.geometry().geometry()->vertexAt( vId ); + layerPoint = f.geometry().constGet()->vertexAt( vId ); return 0; } else diff --git a/src/gui/qgsmaptoolidentify.cpp b/src/gui/qgsmaptoolidentify.cpp index 92314f9ccbd..a3d71290d9f 100644 --- a/src/gui/qgsmaptoolidentify.cpp +++ b/src/gui/qgsmaptoolidentify.cpp @@ -376,14 +376,14 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur if ( feature->hasGeometry() ) { geometryType = feature->geometry().type(); - wkbType = feature->geometry().geometry()->wkbType(); + wkbType = feature->geometry().wkbType(); //find closest vertex to clicked point - closestPoint = QgsGeometryUtils::closestVertex( *feature->geometry().geometry(), QgsPoint( layerPoint.x(), layerPoint.y() ), vId ); + closestPoint = QgsGeometryUtils::closestVertex( *feature->geometry().constGet(), QgsPoint( layerPoint.x(), layerPoint.y() ), vId ); } if ( QgsWkbTypes::isMultiType( wkbType ) ) { - QString str = QLocale::system().toString( static_cast( feature->geometry().geometry() )->numGeometries() ); + QString str = QLocale::system().toString( static_cast( feature->geometry().constGet() )->numGeometries() ); derivedAttributes.insert( tr( "Parts" ), str ); str = QLocale::system().toString( vId.part + 1 ); derivedAttributes.insert( tr( "Part number" ), str ); @@ -396,7 +396,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur QString str = formatDistance( dist ); derivedAttributes.insert( tr( "Length" ), str ); - const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( feature->geometry().geometry() ); + const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( feature->geometry().constGet() ); if ( curve ) { str = QLocale::system().toString( curve->nCoordinates() ); @@ -431,11 +431,11 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur str = formatDistance( perimeter ); derivedAttributes.insert( tr( "Perimeter" ), str ); - str = QLocale::system().toString( feature->geometry().geometry()->nCoordinates() ); + str = QLocale::system().toString( feature->geometry().constGet()->nCoordinates() ); derivedAttributes.insert( tr( "Vertices" ), str ); //add details of closest vertex to identify point - closestVertexAttributes( *feature->geometry().geometry(), vId, layer, derivedAttributes ); + closestVertexAttributes( *feature->geometry().constGet(), vId, layer, derivedAttributes ); } else if ( geometryType == QgsWkbTypes::PointGeometry && QgsWkbTypes::flatType( wkbType ) == QgsWkbTypes::Point ) @@ -449,12 +449,12 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur if ( QgsWkbTypes::hasZ( wkbType ) ) { - str = QLocale::system().toString( static_cast( feature->geometry().geometry() )->z(), 'g', 10 ); + str = QLocale::system().toString( static_cast( feature->geometry().constGet() )->z(), 'g', 10 ); derivedAttributes.insert( QStringLiteral( "Z" ), str ); } if ( QgsWkbTypes::hasM( wkbType ) ) { - str = QLocale::system().toString( static_cast( feature->geometry().geometry() )->m(), 'g', 10 ); + str = QLocale::system().toString( static_cast( feature->geometry().constGet() )->m(), 'g', 10 ); derivedAttributes.insert( QStringLiteral( "M" ), str ); } } diff --git a/src/providers/grass/qgsgrassprovider.cpp b/src/providers/grass/qgsgrassprovider.cpp index d89e761b1fa..a51d4daf93a 100644 --- a/src/providers/grass/qgsgrassprovider.cpp +++ b/src/providers/grass/qgsgrassprovider.cpp @@ -1206,7 +1206,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid ) } QgsFeature feature = mEditBuffer->addedFeatures().value( fid ); QgsGeometry featureGeometry = feature.geometry(); - geometry = featureGeometry.geometry(); + geometry = featureGeometry.constGet(); if ( !geometry ) { QgsDebugMsg( "geometry is null" ); @@ -1222,7 +1222,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid ) if ( wkbType == QgsWkbTypes::Polygon ) { QgsGeometry addedFeatureGeom = addedFeatures[fid].geometry(); - const QgsPolygonV2 *polygon = dynamic_cast( addedFeatureGeom.geometry() ); + const QgsPolygonV2 *polygon = dynamic_cast( addedFeatureGeom.constGet() ); if ( polygon ) { QgsLineString *lineString = polygon->exteriorRing()->curveToLine(); @@ -1662,7 +1662,7 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, const QgsGeometry &g } } - setPoints( mPoints, geom.geometry() ); + setPoints( mPoints, geom.constGet() ); mLayer->map()->lockReadWrite(); // Vect_rewrite_line may delete/write the line with a new id diff --git a/src/server/services/wfs/qgswfsgetfeature.cpp b/src/server/services/wfs/qgswfsgetfeature.cpp index 487a8a7bbef..18df99fe5f3 100644 --- a/src/server/services/wfs/qgswfsgetfeature.cpp +++ b/src/server/services/wfs/qgswfsgetfeature.cpp @@ -1254,7 +1254,7 @@ namespace QgsWfs } else { - QgsAbstractGeometry *abstractGeom = geom.geometry(); + const QgsAbstractGeometry *abstractGeom = geom.constGet(); if ( abstractGeom ) { gmlElem = abstractGeom->asGML2( doc, prec, "http://www.opengis.net/gml" ); @@ -1355,7 +1355,7 @@ namespace QgsWfs } else { - QgsAbstractGeometry *abstractGeom = geom.geometry(); + const QgsAbstractGeometry *abstractGeom = geom.constGet(); if ( abstractGeom ) { gmlElem = abstractGeom->asGML3( doc, prec, "http://www.opengis.net/gml" ); diff --git a/src/server/services/wms/qgswmsrenderer.cpp b/src/server/services/wms/qgswmsrenderer.cpp index 84618b37a39..4a2bab6044e 100644 --- a/src/server/services/wms/qgswmsrenderer.cpp +++ b/src/server/services/wms/qgswmsrenderer.cpp @@ -1613,13 +1613,13 @@ namespace QgsWms if ( segmentizeWktGeometry ) { - QgsAbstractGeometry *abstractGeom = geom.geometry(); + const QgsAbstractGeometry *abstractGeom = geom.constGet(); if ( abstractGeom ) { if ( QgsWkbTypes::isCurvedType( abstractGeom->wkbType() ) ) { QgsAbstractGeometry *segmentizedGeom = abstractGeom->segmentize(); - geom.setGeometry( segmentizedGeom ); + geom.set( segmentizedGeom ); } } } diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index 377476ffc3d..acf52cff358 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -1911,7 +1911,7 @@ void TestQgsProcessing::parameterExtent() QGSCOMPARENEAR( ext.yMinimum(), 30.151856, 0.01 ); QGSCOMPARENEAR( ext.yMaximum(), 30.257289, 0.01 ); QgsGeometry gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:4326" ) ); - QCOMPARE( gExt.geometry()->vertexCount(), 85 ); + QCOMPARE( gExt.constGet()->vertexCount(), 85 ); ext = gExt.boundingBox(); QGSCOMPARENEAR( ext.xMinimum(), 17.924273, 0.01 ); QGSCOMPARENEAR( ext.xMaximum(), 18.045658, 0.01 ); @@ -1948,7 +1948,7 @@ void TestQgsProcessing::parameterExtent() QGSCOMPARENEAR( ext.yMinimum(), 244963, 100 ); QGSCOMPARENEAR( ext.yMaximum(), 490287, 100 ); gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:3785" ) ); - QCOMPARE( gExt.geometry()->vertexCount(), 85 ); + QCOMPARE( gExt.constGet()->vertexCount(), 85 ); ext = gExt.boundingBox(); QGSCOMPARENEAR( ext.xMinimum(), 122451, 100 ); QGSCOMPARENEAR( ext.xMaximum(), 367354, 100 ); @@ -1998,7 +1998,7 @@ void TestQgsProcessing::parameterExtent() // as reprojected geometry gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:3785" ) ); - QCOMPARE( gExt.geometry()->vertexCount(), 85 ); + QCOMPARE( gExt.constGet()->vertexCount(), 85 ); ext = gExt.boundingBox(); QGSCOMPARENEAR( ext.xMinimum(), 122451, 100 ); QGSCOMPARENEAR( ext.xMaximum(), 367354, 100 ); diff --git a/tests/src/app/testqgisappclipboard.cpp b/tests/src/app/testqgisappclipboard.cpp index 9ac8451864a..e662339bc58 100644 --- a/tests/src/app/testqgisappclipboard.cpp +++ b/tests/src/app/testqgisappclipboard.cpp @@ -205,14 +205,14 @@ void TestQgisAppClipboard::pasteWkt() QgsFeatureList features = mQgisApp->clipboard()->copyOf(); QCOMPARE( features.length(), 2 ); QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() ); - QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); + QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); QgsGeometry featureGeom = features.at( 0 ).geometry(); - const QgsPoint *point = dynamic_cast< QgsPoint * >( featureGeom.geometry() ); + const QgsPoint *point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() ); QCOMPARE( point->x(), 125.0 ); QCOMPARE( point->y(), 10.0 ); QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() ); - QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); - point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().geometry() ); + QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); + point = dynamic_cast< const QgsPoint * >( features.at( 1 ).geometry().constGet() ); QCOMPARE( point->x(), 111.0 ); QCOMPARE( point->y(), 30.0 ); @@ -224,15 +224,15 @@ void TestQgisAppClipboard::pasteWkt() QCOMPARE( features.length(), 2 ); QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() ); - QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); + QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); featureGeom = features.at( 0 ).geometry(); - point = dynamic_cast< QgsPoint * >( featureGeom.geometry() ); + point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() ); QCOMPARE( point->x(), 111.0 ); QCOMPARE( point->y(), 30.0 ); QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() ); - QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); - point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().geometry() ); + QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); + point = dynamic_cast< const QgsPoint * >( features.at( 1 ).geometry().constGet() ); QCOMPARE( point->x(), 125.0 ); QCOMPARE( point->y(), 10.0 ); @@ -251,9 +251,9 @@ void TestQgisAppClipboard::pasteGeoJson() QgsFeatureList features = mQgisApp->clipboard()->copyOf( fields ); QCOMPARE( features.length(), 1 ); QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() ); - QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); + QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); QgsGeometry featureGeom = features.at( 0 ).geometry(); - const QgsPoint *point = dynamic_cast< QgsPoint * >( featureGeom.geometry() ); + const QgsPoint *point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() ); QCOMPARE( point->x(), 125.0 ); QCOMPARE( point->y(), 10.0 ); QCOMPARE( features.at( 0 ).attribute( "name" ).toString(), QString( "Dinagat Islands" ) ); diff --git a/tests/src/core/testqgsconnectionpool.cpp b/tests/src/core/testqgsconnectionpool.cpp index 57c604132a5..df4f528e909 100644 --- a/tests/src/core/testqgsconnectionpool.cpp +++ b/tests/src/core/testqgsconnectionpool.cpp @@ -116,7 +116,7 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX() for ( int i = 0, n = layer1Features.count(); i < n; ++i ) { QgsGeometry featureGeom = layer1Features[i].geometry(); - const QgsPoint *geom = dynamic_cast( featureGeom.geometry() ); + const QgsPoint *geom = dynamic_cast( featureGeom.constGet() ); QVERIFY( geom ); QVERIFY( qFuzzyCompare( geom->x(), i ) ); QVERIFY( qFuzzyCompare( geom->y(), i ) ); @@ -124,7 +124,7 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX() for ( int i = 0, n = layer2Features.count(); i < n; ++i ) { QgsGeometry featureGeom = layer2Features[i].geometry(); - const QgsLineString *geom = dynamic_cast( featureGeom.geometry() ); + const QgsLineString *geom = dynamic_cast( featureGeom.constGet() ); QVERIFY( geom ); int nVtx = geom->vertexCount(); QVERIFY( nVtx == nRoutePts ); diff --git a/tests/src/core/testqgsgeometry.cpp b/tests/src/core/testqgsgeometry.cpp index b23aab44572..63514bfb57c 100644 --- a/tests/src/core/testqgsgeometry.cpp +++ b/tests/src/core/testqgsgeometry.cpp @@ -322,74 +322,74 @@ void TestQgsGeometry::copy() { //create a point geometry QgsGeometry original( new QgsPoint( 1.0, 2.0 ) ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //implicitly shared copy QgsGeometry copy( original ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //trigger a detach - copy.setGeometry( new QgsPoint( 3.0, 4.0 ) ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 ); + copy.set( new QgsPoint( 3.0, 4.0 ) ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 ); //make sure original was untouched - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); } void TestQgsGeometry::assignment() { //create a point geometry QgsGeometry original( new QgsPoint( 1.0, 2.0 ) ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //assign to implicitly shared copy QgsGeometry copy; copy = original; - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //trigger a detach - copy.setGeometry( new QgsPoint( 3.0, 4.0 ) ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 ); - QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 ); + copy.set( new QgsPoint( 3.0, 4.0 ) ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 ); + QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 ); //make sure original was untouched - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); } void TestQgsGeometry::asVariant() { //create a point geometry QgsGeometry original( new QgsPoint( 1.0, 2.0 ) ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //convert to and from a QVariant QVariant var = QVariant::fromValue( original ); QVERIFY( var.isValid() ); QgsGeometry fromVar = qvariant_cast( var ); - QCOMPARE( fromVar.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( fromVar.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( fromVar.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( fromVar.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //also check copying variant QVariant var2 = var; QVERIFY( var2.isValid() ); QgsGeometry fromVar2 = qvariant_cast( var2 ); - QCOMPARE( fromVar2.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( fromVar2.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( fromVar2.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( fromVar2.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); //modify original and check detachment - original.setGeometry( new QgsPoint( 3.0, 4.0 ) ); + original.set( new QgsPoint( 3.0, 4.0 ) ); QgsGeometry fromVar3 = qvariant_cast( var ); - QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); - QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); + QCOMPARE( fromVar3.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 ); + QCOMPARE( fromVar3.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 ); } void TestQgsGeometry::isEmpty() @@ -397,10 +397,10 @@ void TestQgsGeometry::isEmpty() QgsGeometry geom; QVERIFY( geom.isNull() ); - geom.setGeometry( new QgsPoint( 1.0, 2.0 ) ); + geom.set( new QgsPoint( 1.0, 2.0 ) ); QVERIFY( !geom.isNull() ); - geom.setGeometry( 0 ); + geom.set( 0 ); QVERIFY( geom.isNull() ); QgsGeometryCollection collection; @@ -412,10 +412,10 @@ void TestQgsGeometry::operatorBool() QgsGeometry geom; QVERIFY( !geom ); - geom.setGeometry( new QgsPoint( 1.0, 2.0 ) ); + geom.set( new QgsPoint( 1.0, 2.0 ) ); QVERIFY( geom ); - geom.setGeometry( 0 ); + geom.set( 0 ); QVERIFY( !geom ); } @@ -15099,10 +15099,10 @@ void TestQgsGeometry::intersectionCheck1() { QVERIFY( mpPolygonGeometryA.intersects( mpPolygonGeometryB ) ); - std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( mpPolygonGeometryA.geometry() ) ); - QVERIFY( engine->intersects( mpPolygonGeometryB.geometry() ) ); + std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( mpPolygonGeometryA.constGet() ) ); + QVERIFY( engine->intersects( mpPolygonGeometryB.constGet() ) ); engine->prepareGeometry(); - QVERIFY( engine->intersects( mpPolygonGeometryB.geometry() ) ); + QVERIFY( engine->intersects( mpPolygonGeometryB.constGet() ) ); // should be a single polygon as A intersect B QgsGeometry mypIntersectionGeometry = mpPolygonGeometryA.intersection( mpPolygonGeometryB ); @@ -15389,7 +15389,7 @@ void TestQgsGeometry::dataStream() ds.device()->seek( 0 ); ds >> resultGeometry; - QCOMPARE( geom.geometry()->asWkt(), resultGeometry.geometry()->asWkt() ); + QCOMPARE( geom.constGet()->asWkt(), resultGeometry.constGet()->asWkt() ); //also test with geometry without data std::unique_ptr emptyGeom( new QgsGeometry() ); @@ -15863,7 +15863,7 @@ void TestQgsGeometry::minimalEnclosingCircle() result = geomTest.minimalEnclosingCircle( center, radius ); QCOMPARE( center, QgsPointXY( 5, 5 ) ); QCOMPARE( radius, 0.0 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); // case 2 @@ -15871,35 +15871,35 @@ void TestQgsGeometry::minimalEnclosingCircle() result = geomTest.minimalEnclosingCircle( center, radius ); QGSCOMPARENEARPOINT( center, QgsPointXY( 5, 6 ), 0.0001 ); QGSCOMPARENEAR( radius, sqrt( 2 ) * 2, 0.0001 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); geomTest = QgsGeometry::fromWkt( QStringLiteral( "LINESTRING( 0 5, 2 2, 0 -5, -1 -1 )" ) ); result = geomTest.minimalEnclosingCircle( center, radius ); QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 ); QGSCOMPARENEAR( radius, 5, 0.0001 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 0 5, 2 2, 0 -5, -1 -1 )" ) ); result = geomTest.minimalEnclosingCircle( center, radius ); QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 ); QGSCOMPARENEAR( radius, 5, 0.0001 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); geomTest = QgsGeometry::fromWkt( QStringLiteral( "POLYGON(( 0 5, 2 2, 0 -5, -1 -1 ))" ) ); result = geomTest.minimalEnclosingCircle( center, radius ); QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 ); QGSCOMPARENEAR( radius, 5, 0.0001 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 0 5, 0 -5, 0 0 )" ) ); result = geomTest.minimalEnclosingCircle( center, radius ); QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 ); QGSCOMPARENEAR( radius, 5, 0.0001 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); // case 3 @@ -15907,7 +15907,7 @@ void TestQgsGeometry::minimalEnclosingCircle() result = geomTest.minimalEnclosingCircle( center, radius ); QGSCOMPARENEARPOINT( center, QgsPointXY( 0.8333, 0.8333 ), 0.0001 ); QGSCOMPARENEAR( radius, 5.8926, 0.0001 ); - resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); + resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) ); QCOMPARE( result, resultTest ); } diff --git a/tests/src/core/testqgsogrutils.cpp b/tests/src/core/testqgsogrutils.cpp index 8376dfebbdf..228862f936f 100644 --- a/tests/src/core/testqgsogrutils.cpp +++ b/tests/src/core/testqgsogrutils.cpp @@ -97,8 +97,8 @@ void TestQgsOgrUtils::ogrGeometryToQgsGeometry() QgsGeometry geom = QgsOgrUtils::ogrGeometryToQgsGeometry( ogrGeom ); QVERIFY( !geom.isNull() ); - QCOMPARE( geom.geometry()->wkbType(), QgsWkbTypes::LineString ); - QCOMPARE( geom.geometry()->nCoordinates(), 71 ); + QCOMPARE( geom.constGet()->wkbType(), QgsWkbTypes::LineString ); + QCOMPARE( geom.constGet()->nCoordinates(), 71 ); OGR_F_Destroy( oFeat ); OGR_DS_Destroy( hDS ); @@ -124,8 +124,8 @@ void TestQgsOgrUtils::readOgrFeatureGeometry() QgsOgrUtils::readOgrFeatureGeometry( oFeat, f ); QVERIFY( f.hasGeometry() ); - QCOMPARE( f.geometry().geometry()->wkbType(), QgsWkbTypes::LineString ); - QCOMPARE( f.geometry().geometry()->nCoordinates(), 71 ); + QCOMPARE( f.geometry().constGet()->wkbType(), QgsWkbTypes::LineString ); + QCOMPARE( f.geometry().constGet()->nCoordinates(), 71 ); OGR_F_Destroy( oFeat ); OGR_DS_Destroy( hDS ); @@ -273,8 +273,8 @@ void TestQgsOgrUtils::readOgrFeature() QCOMPARE( f.attribute( "datetime_field" ), QVariant( QDateTime( QDate( 2005, 3, 5 ), QTime( 6, 45, 0 ) ) ) ); QCOMPARE( f.attribute( "string_field" ), QVariant( "a string" ) ); QVERIFY( f.hasGeometry() ); - QCOMPARE( f.geometry().geometry()->wkbType(), QgsWkbTypes::LineString ); - QCOMPARE( f.geometry().geometry()->nCoordinates(), 71 ); + QCOMPARE( f.geometry().constGet()->wkbType(), QgsWkbTypes::LineString ); + QCOMPARE( f.geometry().constGet()->nCoordinates(), 71 ); OGR_F_Destroy( oFeat ); OGR_DS_Destroy( hDS ); @@ -331,9 +331,9 @@ void TestQgsOgrUtils::stringToFeatureList() features = QgsOgrUtils::stringToFeatureList( QStringLiteral( "{\n\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\",\"coordinates\": [125, 10]},\"properties\": {\"name\": \"Dinagat Islands\"}}" ), fields, QTextCodec::codecForName( "System" ) ); QCOMPARE( features.length(), 1 ); QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() ); - QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); + QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); QgsGeometry featureGeom = features.at( 0 ).geometry(); - const QgsPoint *point = dynamic_cast< QgsPoint * >( featureGeom.geometry() ); + const QgsPoint *point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() ); QCOMPARE( point->x(), 125.0 ); QCOMPARE( point->y(), 10.0 ); QCOMPARE( features.at( 0 ).attribute( "name" ).toString(), QString( "Dinagat Islands" ) ); @@ -343,16 +343,16 @@ void TestQgsOgrUtils::stringToFeatureList() " {\n\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\",\"coordinates\": [110, 20]},\"properties\": {\"name\": \"Henry Gale Island\"}}]}", fields, QTextCodec::codecForName( "System" ) ); QCOMPARE( features.length(), 2 ); QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() ); - QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); + QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); featureGeom = features.at( 0 ).geometry(); - point = dynamic_cast< QgsPoint * >( featureGeom.geometry() ); + point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() ); QCOMPARE( point->x(), 125.0 ); QCOMPARE( point->y(), 10.0 ); QCOMPARE( features.at( 0 ).attribute( "name" ).toString(), QString( "Dinagat Islands" ) ); QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() ); - QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point ); + QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point ); featureGeom = features.at( 1 ).geometry(); - point = dynamic_cast< QgsPoint * >( featureGeom.geometry() ); + point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() ); QCOMPARE( point->x(), 110.0 ); QCOMPARE( point->y(), 20.0 ); QCOMPARE( features.at( 1 ).attribute( "name" ).toString(), QString( "Henry Gale Island" ) ); diff --git a/tests/src/core/testqgspointlocator.cpp b/tests/src/core/testqgspointlocator.cpp index 93272539387..8513f81951a 100644 --- a/tests/src/core/testqgspointlocator.cpp +++ b/tests/src/core/testqgspointlocator.cpp @@ -286,7 +286,7 @@ class TestQgsPointLocator : public QObject QgsVectorLayer *vlEmptyGeom = new QgsVectorLayer( QStringLiteral( "Polygon" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) ); QgsFeature ff( 0 ); QgsGeometry g; - g.setGeometry( new QgsPolygonV2() ); + g.set( new QgsPolygonV2() ); ff.setGeometry( g ); QgsFeatureList flist; flist << ff; diff --git a/tests/src/geometry_checker/testqgsgeometrychecks.cpp b/tests/src/geometry_checker/testqgsgeometrychecks.cpp index 4741ba0ebe1..89281b8108d 100644 --- a/tests/src/geometry_checker/testqgsgeometrychecks.cpp +++ b/tests/src/geometry_checker/testqgsgeometrychecks.cpp @@ -141,21 +141,21 @@ void TestQgsGeometryChecks::testAngleCheck() int n1, n2; context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f ); - n1 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); + n1 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); QVERIFY( fixCheckError( errs1[0], QgsGeometryAngleCheck::DeleteNode, QgsGeometryCheckError::StatusFixed, {{errs1[0]->layerId(), errs1[0]->featureId(), QgsGeometryCheck::ChangeNode, QgsGeometryCheck::ChangeRemoved, errs1[0]->vidx()}} ) ); context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f ); - n2 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); + n2 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); QCOMPARE( n1, n2 + 1 ); context->featurePools[errs2[0]->layerId()]->get( errs2[0]->featureId(), f ); - n1 = f.geometry().geometry()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring ); + n1 = f.geometry().constGet()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring ); QVERIFY( fixCheckError( errs2[0], QgsGeometryAngleCheck::DeleteNode, QgsGeometryCheckError::StatusFixed, {{errs2[0]->layerId(), errs2[0]->featureId(), QgsGeometryCheck::ChangeNode, QgsGeometryCheck::ChangeRemoved, errs2[0]->vidx()}} ) ); context->featurePools[errs2[0]->layerId()]->get( errs2[0]->featureId(), f ); - n2 = f.geometry().geometry()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring ); + n2 = f.geometry().constGet()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring ); QCOMPARE( n1, n2 + 1 ); // Test change tracking @@ -455,12 +455,12 @@ void TestQgsGeometryChecks::testDuplicateNodesCheck() QgsFeature f; context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f ); - int n1 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); + int n1 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); QVERIFY( fixCheckError( errs1[0], QgsGeometryDuplicateNodesCheck::RemoveDuplicates, QgsGeometryCheckError::StatusFixed, {{errs1[0]->layerId(), errs1[0]->featureId(), QgsGeometryCheck::ChangeNode, QgsGeometryCheck::ChangeRemoved, errs1[0]->vidx()}} ) ); context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f ); - int n2 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); + int n2 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring ); QCOMPARE( n1, n2 + 1 ); cleanupTestContext( context ); @@ -562,7 +562,7 @@ void TestQgsGeometryChecks::testHoleCheck() {errs1[0]->layerId(), errs1[0]->featureId(), QgsGeometryCheck::ChangeRing, QgsGeometryCheck::ChangeRemoved, QgsVertexId( 0, 1 )} } ) ); context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f ); - QVERIFY( f.geometry().geometry()->ringCount( 0 ) == 1 ); + QVERIFY( f.geometry().constGet()->ringCount( 0 ) == 1 ); cleanupTestContext( context ); } @@ -867,11 +867,11 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck() {errs1[0]->layerId(), nextId, QgsGeometryCheck::ChangeFeature, QgsGeometryCheck::ChangeAdded, QgsVertexId()} } ) ); context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f ); - QCOMPARE( f.geometry().geometry()->partCount(), 1 ); - QCOMPARE( f.geometry().geometry()->vertexCount(), 4 ); + QCOMPARE( f.geometry().constGet()->partCount(), 1 ); + QCOMPARE( f.geometry().constGet()->vertexCount(), 4 ); context->featurePools[errs1[0]->layerId()]->get( nextId, f ); - QCOMPARE( f.geometry().geometry()->partCount(), 1 ); - QCOMPARE( f.geometry().geometry()->vertexCount(), 6 ); + QCOMPARE( f.geometry().constGet()->partCount(), 1 ); + QCOMPARE( f.geometry().constGet()->vertexCount(), 6 ); QVERIFY( fixCheckError( errs2[0], QgsGeometrySelfIntersectionCheck::ToMultiObject, QgsGeometryCheckError::StatusFixed, @@ -881,9 +881,9 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck() {errs2[0]->layerId(), errs2[0]->featureId(), QgsGeometryCheck::ChangePart, QgsGeometryCheck::ChangeAdded, QgsVertexId( 1 )} } ) ); context->featurePools[errs2[0]->layerId()]->get( errs2[0]->featureId(), f ); - QCOMPARE( f.geometry().geometry()->partCount(), 2 ); - QCOMPARE( f.geometry().geometry()->vertexCount( 0 ), 4 ); - QCOMPARE( f.geometry().geometry()->vertexCount( 1 ), 5 ); + QCOMPARE( f.geometry().constGet()->partCount(), 2 ); + QCOMPARE( f.geometry().constGet()->vertexCount( 0 ), 4 ); + QCOMPARE( f.geometry().constGet()->vertexCount( 1 ), 5 ); nextId = context->featurePools[errs3[0]->layerId()]->getLayer()->featureCount(); QVERIFY( fixCheckError( errs3[0], @@ -893,11 +893,11 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck() {errs3[0]->layerId(), nextId, QgsGeometryCheck::ChangeFeature, QgsGeometryCheck::ChangeAdded, QgsVertexId()} } ) ); context->featurePools[errs3[0]->layerId()]->get( errs3[0]->featureId(), f ); - QCOMPARE( f.geometry().geometry()->partCount(), 1 ); - QCOMPARE( f.geometry().geometry()->vertexCount(), 6 ); + QCOMPARE( f.geometry().constGet()->partCount(), 1 ); + QCOMPARE( f.geometry().constGet()->vertexCount(), 6 ); context->featurePools[errs3[0]->layerId()]->get( nextId, f ); - QCOMPARE( f.geometry().geometry()->partCount(), 1 ); - QCOMPARE( f.geometry().geometry()->vertexCount(), 4 ); + QCOMPARE( f.geometry().constGet()->partCount(), 1 ); + QCOMPARE( f.geometry().constGet()->vertexCount(), 4 ); QVERIFY( fixCheckError( errs4[0], QgsGeometrySelfIntersectionCheck::ToMultiObject, QgsGeometryCheckError::StatusFixed, @@ -907,12 +907,12 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck() {errs4[0]->layerId(), errs4[0]->featureId(), QgsGeometryCheck::ChangePart, QgsGeometryCheck::ChangeAdded, QgsVertexId( 1 )} } ) ); context->featurePools[errs4[0]->layerId()]->get( errs4[0]->featureId(), f ); - QCOMPARE( f.geometry().geometry()->partCount(), 2 ); - QCOMPARE( f.geometry().geometry()->ringCount( 0 ), 1 ); - QCOMPARE( f.geometry().geometry()->vertexCount( 0, 0 ), 5 ); - QCOMPARE( f.geometry().geometry()->ringCount( 1 ), 2 ); - QCOMPARE( f.geometry().geometry()->vertexCount( 1, 0 ), 5 ); - QCOMPARE( f.geometry().geometry()->vertexCount( 1, 1 ), 5 ); + QCOMPARE( f.geometry().constGet()->partCount(), 2 ); + QCOMPARE( f.geometry().constGet()->ringCount( 0 ), 1 ); + QCOMPARE( f.geometry().constGet()->vertexCount( 0, 0 ), 5 ); + QCOMPARE( f.geometry().constGet()->ringCount( 1 ), 2 ); + QCOMPARE( f.geometry().constGet()->vertexCount( 1, 0 ), 5 ); + QCOMPARE( f.geometry().constGet()->vertexCount( 1, 1 ), 5 ); // Test change tracking QgsGeometrySelfIntersectionCheckError *err = static_cast( errs4[0] );