diff --git a/doc/api_break.dox b/doc/api_break.dox
index 1c3d6f159f4..22191d2fd13 100644
--- a/doc/api_break.dox
+++ b/doc/api_break.dox
@@ -212,6 +212,15 @@ attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()
+\subsection qgis_api_break_3_0_QgsFeature QgsFeature
+
+
+- geometryAndOwnership() has been removed. Use geometry() instead.
+- setGeometryAndOwnership() has been removed. Use setGeometry() instead.
+- The setGeometry( QgsGeometry* ) method has been removed, use setGeometry( const QgsGeometry& ) instead.
+- setFields( const QgsFields*, bool ) has been removed, use setFields( const QgsFields&, bool ) instead.
+
+
\subsection qgis_api_break_3_0_QgsGroupWMSDataDialog QgsGroupWMSDataDialog
@@ -384,6 +393,12 @@ be returned instead of a null pointer if no transformation is required.
- setCoordinateTransform() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.
+\subsection qgis_api_break_3_0_QgsRubberBand QgsRubberBand
+
+
+- setToGeometry() and addGeometry() now take geometry references, not pointers.
+
+
\subsection qgis_api_break_3_0_QgsPalLayerSettings QgsPalLayerSettings
@@ -418,6 +433,15 @@ plugins calling this method will need to be updated.
setExcludeAttributesWms()
- excludeAttributesWFS() and setExcludeAttributesWFS() have been renamed to excludeAttributesWfs() and
setExcludeAttributesWfs()
+- changeGeometry() now accepts a geometry reference, not a pointer.
+- The geometryChanged() signal now uses a const QgsGeometry reference.
+
+
+\subsection qgis_api_break_3_0_QgsVectorLayerEditBuffer QgsVectorLayerEditBuffer
+
+
+- changeGeometry() now accepts a geometry reference, not a pointer.
+- The geometryChanged() signal now uses a const QgsGeometry reference.
\subsection qgis_api_break_3_0_QgsVectorLayerImport QgsVectorLayerImport
@@ -429,6 +453,13 @@ pointers makes for more robust, safer code. Use an invalid (default constructed)
in code which previously passed a null pointer to QgsVectorLayerImport.
+\subsection qgis_api_break_3_0_QgsVectorLayerUndoCommand QgsVectorLayerUndoCommand
+
+
+- QgsVectorLayerUndoCommandChangeGeometry constructor now accepts a geometry reference, not a pointer.
+
+
+
\subsection qgis_api_break_3_0_QgsPointLocator QgsPointLocator
diff --git a/python/core/qgsfeature.sip b/python/core/qgsfeature.sip
index 596f8a839fe..edd54710907 100644
--- a/python/core/qgsfeature.sip
+++ b/python/core/qgsfeature.sip
@@ -333,7 +333,6 @@ class QgsFeature
*
* @returns pointer to feature's geometry
* @see constGeometry
- * @see geometryAndOwnership
* @see setGeometry
*/
QgsGeometry* geometry();
@@ -351,58 +350,14 @@ class QgsFeature
*/
const QgsGeometry* constGeometry() const;
- /** Get the geometry object associated with this feature, and transfer ownership of the
- * geometry to the caller. The caller assumes responsibility for the QgsGeometry*'s destruction.
- * @returns pointer to feature's geometry
- * @see geometry
- * @see setGeometry
- * @deprecated use constGeometry() instead
- */
- QgsGeometry *geometryAndOwnership() /Factory,Deprecated/;
-
/** Set this feature's geometry from another QgsGeometry object. This method performs a deep copy
* of the geometry.
* @param geom new feature geometry
* @see geometry
* @see constGeometry
- * @see geometryAndOwnership
- * @see setGeometryAndOwnership
*/
void setGeometry( const QgsGeometry& geom );
- /** Set this feature's geometry from a QgsGeometry pointer. Ownership of the geometry is transferred
- * to the feature.
- * @param geom new feature geometry
- * @note not available in python bindings
- * @see geometry
- * @see constGeometry
- * @see geometryAndOwnership
- * @see setGeometryAndOwnership
- */
- // void setGeometry( QgsGeometry* geom /Transfer/ );
-
- /** Set this feature's geometry from WKB. This feature assumes responsibility for destroying the
- * created geometry.
- * @param geom geometry as WKB
- * @param length size of WKB
- * @see setGeometry
- * @see geometry
- * @see constGeometry
- * @see geometryAndOwnership
- * @deprecated will be removed in QGIS 3.0
- */
- void setGeometryAndOwnership( unsigned char * geom /Transfer/, int length ) /Deprecated/;
-
- /** Assign a field map with the feature to allow attribute access by attribute name.
- * @param fields The attribute fields which this feature holds
- * @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
- * C++: Defaults to false
- * Python: Defaults to true
- * @deprecated use setFields( const QgsFields& fields, bool initAttributes = false ) instead
- * @note not available in Python bindings
- */
- //void setFields( const QgsFields* fields, bool initAttributes = true );
-
/** Assign a field map with the feature to allow attribute access by attribute name.
* @param fields The attribute fields which this feature holds
* @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip
index 60f07abed38..0833e65a495 100644
--- a/python/core/qgsvectorlayer.sip
+++ b/python/core/qgsvectorlayer.sip
@@ -911,7 +911,7 @@ class QgsVectorLayer : QgsMapLayer
bool setReadOnly( bool readonly = true );
/** Change feature's geometry */
- bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
+ bool changeGeometry( QgsFeatureId fid, const QgsGeometry& geom );
/**
* Changes an attribute value (but does not commit it)
@@ -1615,7 +1615,7 @@ class QgsVectorLayer : QgsMapLayer
* @param fid The id of the changed feature
* @param geometry The new geometry
*/
- void geometryChanged( QgsFeatureId fid, QgsGeometry& geometry );
+ void geometryChanged( QgsFeatureId fid, const QgsGeometry& geometry );
/** This signal is emitted, when attributes are deleted from the provider */
void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
diff --git a/python/core/qgsvectorlayereditbuffer.sip b/python/core/qgsvectorlayereditbuffer.sip
index 2496aacc6e2..2f08f7a2018 100644
--- a/python/core/qgsvectorlayereditbuffer.sip
+++ b/python/core/qgsvectorlayereditbuffer.sip
@@ -31,7 +31,7 @@ class QgsVectorLayerEditBuffer : QObject
virtual bool deleteFeatures( const QgsFeatureIds& fid );
/** Change feature's geometry */
- virtual bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
+ virtual bool changeGeometry( QgsFeatureId fid, QgsGeometry geom );
/** Changed an attribute value (but does not commit it) */
virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
@@ -145,7 +145,7 @@ class QgsVectorLayerEditBuffer : QObject
void featureAdded( QgsFeatureId fid );
void featureDeleted( QgsFeatureId fid );
- void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
+ void geometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
void attributeAdded( int idx );
void attributeDeleted( int idx );
diff --git a/python/core/qgsvectorlayereditpassthrough.sip b/python/core/qgsvectorlayereditpassthrough.sip
index c00cc77d15d..e8caae1178a 100644
--- a/python/core/qgsvectorlayereditpassthrough.sip
+++ b/python/core/qgsvectorlayereditpassthrough.sip
@@ -10,7 +10,7 @@ class QgsVectorLayerEditPassthrough : QgsVectorLayerEditBuffer
bool addFeatures( QgsFeatureList& features );
bool deleteFeature( QgsFeatureId fid );
bool deleteFeatures( const QgsFeatureIds& fids );
- bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
+ bool changeGeometry( QgsFeatureId fid, QgsGeometry geom );
bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
bool addAttribute( const QgsField &field );
bool deleteAttribute( int attr );
diff --git a/python/core/qgsvectorlayerundocommand.sip b/python/core/qgsvectorlayerundocommand.sip
index 7bd3c5575d1..acaa00fe65b 100644
--- a/python/core/qgsvectorlayerundocommand.sip
+++ b/python/core/qgsvectorlayerundocommand.sip
@@ -87,7 +87,7 @@ class QgsVectorLayerUndoCommandChangeGeometry : QgsVectorLayerUndoCommand
* @param fid feature ID of feature to modify geometry of
* @param newGeom new geometry for feature
*/
- QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer /Transfer/, QgsFeatureId fid, QgsGeometry* newGeom /Transfer/ );
+ QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer /Transfer/, QgsFeatureId fid, QgsGeometry newGeom );
~QgsVectorLayerUndoCommandChangeGeometry();
virtual void undo();
diff --git a/python/gui/qgsrubberband.sip b/python/gui/qgsrubberband.sip
index aa4d34f1399..2ab339d1629 100644
--- a/python/gui/qgsrubberband.sip
+++ b/python/gui/qgsrubberband.sip
@@ -170,7 +170,7 @@ class QgsRubberBand: QgsMapCanvasItem
* @param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
- void setToGeometry( const QgsGeometry *geom, QgsVectorLayer* layer );
+ void setToGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
/**
* Sets this rubber band to a map canvas rectangle
@@ -189,7 +189,7 @@ class QgsRubberBand: QgsMapCanvasItem
* @param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
- void addGeometry( const QgsGeometry *geom, QgsVectorLayer* layer );
+ void addGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
/**
* Adds translation to original coordinates (all in map coordinates)
diff --git a/src/analysis/interpolation/DualEdgeTriangulation.cc b/src/analysis/interpolation/DualEdgeTriangulation.cc
index adfe0eeada8..f51a3cea80d 100644
--- a/src/analysis/interpolation/DualEdgeTriangulation.cc
+++ b/src/analysis/interpolation/DualEdgeTriangulation.cc
@@ -3139,7 +3139,8 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
lineGeom.push_back( QgsPoint( p1->getX(), p1->getY() ) );
lineGeom.push_back( QgsPoint( p2->getX(), p2->getY() ) );
QgsGeometry* geom = QgsGeometry::fromPolyline( lineGeom );
- edgeLineFeature.setGeometry( geom );
+ edgeLineFeature.setGeometry( *geom );
+ delete geom;
edgeLineFeature.initAttributes( 1 );
//attributes
diff --git a/src/analysis/vector/qgsgeometryanalyzer.cpp b/src/analysis/vector/qgsgeometryanalyzer.cpp
index be3092895e6..7fb867083df 100644
--- a/src/analysis/vector/qgsgeometryanalyzer.cpp
+++ b/src/analysis/vector/qgsgeometryanalyzer.cpp
@@ -138,7 +138,8 @@ void QgsGeometryAnalyzer::simplifyFeature( QgsFeature& f, QgsVectorFileWriter* v
tmpGeometry = featureGeometry->simplify( tolerance );
QgsFeature newFeature;
- newFeature.setGeometry( tmpGeometry );
+ newFeature.setGeometry( *tmpGeometry );
+ delete tmpGeometry;
newFeature.setAttributes( f.attributes() );
//add it to vector file writer
@@ -254,7 +255,8 @@ void QgsGeometryAnalyzer::centroidFeature( QgsFeature& f, QgsVectorFileWriter* v
tmpGeometry = featureGeometry->centroid();
QgsFeature newFeature;
- newFeature.setGeometry( tmpGeometry );
+ newFeature.setGeometry( *tmpGeometry );
+ delete tmpGeometry;
newFeature.setAttributes( f.attributes() );
//add it to vector file writer
@@ -331,7 +333,9 @@ bool QgsGeometryAnalyzer::extent( QgsVectorLayer* layer,
attrs[8] = QVariant( height );
attrs[9] = QVariant( width );
feat.setAttributes( attrs );
- feat.setGeometry( QgsGeometry::fromRect( rect ) );
+ QgsGeometry* g = QgsGeometry::fromRect( rect );
+ feat.setGeometry( *g );
+ delete g;
vWriter.addFeature( feat );
return true;
}
@@ -493,7 +497,8 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
attributes[2] = values.at( 1 );
QgsFeature dissolveFeature;
dissolveFeature.setAttributes( attributes );
- dissolveFeature.setGeometry( dissolveGeometry );
+ dissolveFeature.setGeometry( *dissolveGeometry );
+ delete dissolveGeometry;
vWriter.addFeature( dissolveFeature );
}
//take all features
@@ -540,7 +545,8 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
attributes[2] = QVariant( values[ 1 ] );
QgsFeature dissolveFeature;
dissolveFeature.setAttributes( attributes );
- dissolveFeature.setGeometry( dissolveGeometry );
+ dissolveFeature.setGeometry( *dissolveGeometry );
+ delete dissolveGeometry;
vWriter.addFeature( dissolveFeature );
}
}
@@ -702,7 +708,8 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
++jt;
}
}
- outputFeature.setGeometry( dissolveGeometry );
+ outputFeature.setGeometry( *dissolveGeometry );
+ delete dissolveGeometry;
vWriter.addFeature( outputFeature );
}
return true;
@@ -831,7 +838,8 @@ bool QgsGeometryAnalyzer::buffer( QgsVectorLayer* layer, const QString& shapefil
QgsDebugMsg( "no dissolved geometry - should not happen" );
return false;
}
- dissolveFeature.setGeometry( dissolveGeometry );
+ dissolveFeature.setGeometry( *dissolveGeometry );
+ delete dissolveGeometry;
vWriter.addFeature( dissolveFeature );
}
return true;
@@ -878,7 +886,8 @@ void QgsGeometryAnalyzer::bufferFeature( QgsFeature& f, int nProcessedFeatures,
else //dissolve
{
QgsFeature newFeature;
- newFeature.setGeometry( bufferGeometry );
+ newFeature.setGeometry( *bufferGeometry );
+ delete bufferGeometry;
newFeature.setAttributes( f.attributes() );
//add it to vector file writer
@@ -990,7 +999,8 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
if ( lrsGeom )
{
++nOutputFeatures;
- addEventLayerFeature( fet, lrsGeom, featureIdIt->geometry(), fileWriter, memoryProviderFeatures, offsetField, offsetScale, forceSingleGeometry );
+ addEventLayerFeature( fet, lrsGeom, featureIdIt->constGeometry() ? *featureIdIt->constGeometry() :
+ QgsGeometry(), fileWriter, memoryProviderFeatures, offsetField, offsetScale, forceSingleGeometry );
}
}
if ( nOutputFeatures < 1 )
@@ -1012,7 +1022,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
return true;
}
-void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry* geom, QgsGeometry* lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures,
+void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry* geom, const QgsGeometry& lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures,
int offsetField, double offsetScale, bool forceSingleType )
{
if ( !geom )
@@ -1045,7 +1055,7 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
}
}
- feature.setGeometry( *geomIt );
+ feature.setGeometry( **geomIt );
if ( fileWriter )
{
fileWriter->addFeature( feature );
@@ -1062,9 +1072,9 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
}
}
-bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset )
+bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, const QgsGeometry& lineGeom, double offset )
{
- if ( !geom || !lineGeom )
+ if ( !geom || lineGeom.isEmpty() )
{
return false;
}
@@ -1147,16 +1157,16 @@ bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
return true;
}
-QgsPoint QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const
+QgsPoint QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist, const QgsGeometry& lineGeom ) const
{
QgsPoint p( x, y );
QgsPoint minDistPoint;
int afterVertexNr;
- lineGeom->closestSegmentWithContext( p, minDistPoint, afterVertexNr );
+ lineGeom.closestSegmentWithContext( p, minDistPoint, afterVertexNr );
int beforeVertexNr = afterVertexNr - 1;
- QgsPoint beforeVertex = lineGeom->vertexAt( beforeVertexNr );
- QgsPoint afterVertex = lineGeom->vertexAt( afterVertexNr );
+ QgsPoint beforeVertex = lineGeom.vertexAt( beforeVertexNr );
+ QgsPoint afterVertex = lineGeom.vertexAt( afterVertexNr );
//get normal vector
double dx = afterVertex.x() - beforeVertex.x();
diff --git a/src/analysis/vector/qgsgeometryanalyzer.h b/src/analysis/vector/qgsgeometryanalyzer.h
index fecfe2251ab..5c5b84332eb 100644
--- a/src/analysis/vector/qgsgeometryanalyzer.h
+++ b/src/analysis/vector/qgsgeometryanalyzer.h
@@ -142,14 +142,14 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
void dissolveFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry** dissolveGeometry );
//helper functions for event layer
- void addEventLayerFeature( QgsFeature& feature, QgsGeometry* geom, QgsGeometry* lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures, int offsetField = -1, double offsetScale = 1.0,
+ void addEventLayerFeature( QgsFeature& feature, QgsGeometry* geom, const QgsGeometry& lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures, int offsetField = -1, double offsetScale = 1.0,
bool forceSingleType = false );
/** Create geometry offset relative to line geometry.
@param geom the geometry to modify
@param lineGeom the line geometry to which the feature is referenced
@param offset the offset value in layer unit. Negative values mean offset towards left, positive values offset to the right side*/
- bool createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset );
- QgsPoint createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const;
+ bool createOffsetGeometry( QgsGeometry* geom, const QgsGeometry& lineGeom, double offset );
+ QgsPoint createPointOffset( double x, double y, double dist, const QgsGeometry& lineGeom ) const;
QgsConstWkbPtr locateBetweenWkbString( QgsConstWkbPtr ptr, QgsMultiPolyline& result, double fromMeasure, double toMeasure );
QgsConstWkbPtr locateAlongWkbString( QgsConstWkbPtr ptr, QgsMultiPoint& result, double measure );
static bool clipSegmentByRange( double x1, double y1, double m1, double x2, double y2, double m2, double range1, double range2, QgsPoint& pt1, QgsPoint& pt2, bool& secondPointClipped );
diff --git a/src/analysis/vector/qgsoverlayanalyzer.cpp b/src/analysis/vector/qgsoverlayanalyzer.cpp
index bc1dcbb5c43..a2b9fefa367 100644
--- a/src/analysis/vector/qgsoverlayanalyzer.cpp
+++ b/src/analysis/vector/qgsoverlayanalyzer.cpp
@@ -169,7 +169,8 @@ void QgsOverlayAnalyzer::intersectFeature( QgsFeature& f, QgsVectorFileWriter* v
{
intersectGeometry = featureGeometry->intersection( overlayFeature.constGeometry() );
- outFeature.setGeometry( intersectGeometry );
+ outFeature.setGeometry( *intersectGeometry );
+ delete intersectGeometry;
QgsAttributes attributesA = f.attributes();
QgsAttributes attributesB = overlayFeature.attributes();
combineAttributeMaps( attributesA, attributesB );
diff --git a/src/analysis/vector/qgspointsample.cpp b/src/analysis/vector/qgspointsample.cpp
index 390e7ad49f5..c925ed45fc8 100644
--- a/src/analysis/vector/qgspointsample.cpp
+++ b/src/analysis/vector/qgspointsample.cpp
@@ -127,7 +127,8 @@ void QgsPointSample::addSamplePoints( QgsFeature& inputFeature, QgsVectorFileWri
f.setAttribute( "id", mNCreatedPoints + 1 );
f.setAttribute( "station_id", points + 1 );
f.setAttribute( "stratum_id", inputFeature.id() );
- f.setGeometry( ptGeom );
+ f.setGeometry( *ptGeom );
+ delete ptGeom;
writer.addFeature( f );
sIndex.insertFeature( f );
pointMapForFeature.insert( mNCreatedPoints, randPoint );
diff --git a/src/analysis/vector/qgstransectsample.cpp b/src/analysis/vector/qgstransectsample.cpp
index 4fbec5fdc51..e5c7aff167b 100644
--- a/src/analysis/vector/qgstransectsample.cpp
+++ b/src/analysis/vector/qgstransectsample.cpp
@@ -171,8 +171,8 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
//find baseline for strata
QVariant strataId = fet.attribute( mStrataIdAttribute );
- QgsGeometry* baselineGeom = findBaselineGeometry( strataId.isValid() ? strataId : -1 );
- if ( !baselineGeom )
+ QgsGeometry baselineGeom = findBaselineGeometry( strataId.isValid() ? strataId : -1 );
+ if ( baselineGeom.isEmpty() )
{
continue;
}
@@ -186,7 +186,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
minDistanceLayerUnits = minDistance / 111319.9;
}
- QgsGeometry* clippedBaseline = strataGeom->intersection( baselineGeom );
+ QgsGeometry* clippedBaseline = strataGeom->intersection( &baselineGeom );
if ( !clippedBaseline || clippedBaseline->wkbType() == Qgis::WKBUnknown )
{
delete clippedBaseline;
@@ -213,7 +213,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
int nMaxIterations = nTransects * 50;
QgsSpatialIndex sIndex; //to check minimum distance
- QMap< QgsFeatureId, QgsGeometry* > lineFeatureMap;
+ QMap< QgsFeatureId, QgsGeometry > lineFeatureMap;
while ( nCreatedTransects < nTransects && nIterations < nMaxIterations )
{
@@ -228,7 +228,8 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
QgsPoint latLongSamplePoint = toLatLongTransform.transform( sampleQgsPoint );
QgsFeature samplePointFeature( outputPointFields );
- samplePointFeature.setGeometry( samplePoint );
+ samplePointFeature.setGeometry( *samplePoint );
+ delete samplePoint;
samplePointFeature.setAttribute( "id", nTotalTransects + 1 );
samplePointFeature.setAttribute( "station_id", nCreatedTransects + 1 );
samplePointFeature.setAttribute( "stratum_id", strataId );
@@ -301,7 +302,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
QgsFeatureId fid( nCreatedTransects );
QgsFeature sampleLineFeature( outputPointFields, fid );
- sampleLineFeature.setGeometry( lineClipStratum );
+ sampleLineFeature.setGeometry( *lineClipStratum );
sampleLineFeature.setAttribute( "id", nTotalTransects + 1 );
sampleLineFeature.setAttribute( "station_id", nCreatedTransects + 1 );
sampleLineFeature.setAttribute( "stratum_id", strataId );
@@ -316,10 +317,9 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
outputPointWriter.addFeature( samplePointFeature );
sIndex.insertFeature( sampleLineFeature );
- Q_NOWARN_DEPRECATED_PUSH
- lineFeatureMap.insert( fid, sampleLineFeature.geometryAndOwnership() );
- Q_NOWARN_DEPRECATED_POP
+ lineFeatureMap.insert( fid, *lineClipStratum );
+ delete lineClipStratum;
delete lineFarAwayGeom;
++nTotalTransects;
++nCreatedTransects;
@@ -327,20 +327,12 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
delete clippedBaseline;
QgsFeature bufferClipFeature;
- bufferClipFeature.setGeometry( bufferLineClipped );
+ bufferClipFeature.setGeometry( *bufferLineClipped );
+ delete bufferLineClipped;
bufferClipFeature.setAttribute( "id", strataId );
bufferClipLineWriter.addFeature( bufferClipFeature );
//delete bufferLineClipped;
- //delete all line geometries in spatial index
- QMap< QgsFeatureId, QgsGeometry* >::iterator featureMapIt = lineFeatureMap.begin();
- for ( ; featureMapIt != lineFeatureMap.end(); ++featureMapIt )
- {
- delete( featureMapIt.value() );
- }
- lineFeatureMap.clear();
- delete baselineGeom;
-
++nFeatures;
}
@@ -352,11 +344,11 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
return 0;
}
-QgsGeometry* QgsTransectSample::findBaselineGeometry( const QVariant& strataId )
+QgsGeometry QgsTransectSample::findBaselineGeometry( const QVariant& strataId )
{
if ( !mBaselineLayer )
{
- return nullptr;
+ return QgsGeometry();
}
QgsFeatureIterator baseLineIt = mBaselineLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QStringList( mBaselineStrataId ), mBaselineLayer->fields() ) );
@@ -366,16 +358,14 @@ QgsGeometry* QgsTransectSample::findBaselineGeometry( const QVariant& strataId )
{
if ( strataId == fet.attribute( mBaselineStrataId ) || mShareBaseline )
{
- Q_NOWARN_DEPRECATED_PUSH
- return fet.geometryAndOwnership();
- Q_NOWARN_DEPRECATED_POP
+ return fet.constGeometry() ? *fet.constGeometry() : QgsGeometry();
}
}
- return nullptr;
+ return QgsGeometry();
}
bool QgsTransectSample::otherTransectWithinDistance( QgsGeometry* geom, double minDistLayerUnit, double minDistance, QgsSpatialIndex& sIndex,
- const QMap< QgsFeatureId, QgsGeometry* >& lineFeatureMap, QgsDistanceArea& da )
+ const QMap< QgsFeatureId, QgsGeometry >& lineFeatureMap, QgsDistanceArea& da )
{
if ( !geom )
{
@@ -393,12 +383,12 @@ bool QgsTransectSample::otherTransectWithinDistance( QgsGeometry* geom, double m
QList::const_iterator lineIdIt = lineIdList.constBegin();
for ( ; lineIdIt != lineIdList.constEnd(); ++lineIdIt )
{
- const QMap< QgsFeatureId, QgsGeometry* >::const_iterator idMapIt = lineFeatureMap.find( *lineIdIt );
+ const QMap< QgsFeatureId, QgsGeometry >::const_iterator idMapIt = lineFeatureMap.find( *lineIdIt );
if ( idMapIt != lineFeatureMap.constEnd() )
{
double dist = 0;
QgsPoint pt1, pt2;
- closestSegmentPoints( *geom, *( idMapIt.value() ), dist, pt1, pt2 );
+ closestSegmentPoints( *geom, idMapIt.value(), dist, pt1, pt2 );
dist = da.measureLine( pt1, pt2 ); //convert degrees to meters if necessary
if ( dist < minDistance )
@@ -413,7 +403,7 @@ bool QgsTransectSample::otherTransectWithinDistance( QgsGeometry* geom, double m
return false;
}
-bool QgsTransectSample::closestSegmentPoints( QgsGeometry& g1, QgsGeometry& g2, double& dist, QgsPoint& pt1, QgsPoint& pt2 )
+bool QgsTransectSample::closestSegmentPoints( const QgsGeometry& g1, const QgsGeometry& g2, double& dist, QgsPoint& pt1, QgsPoint& pt2 )
{
Qgis::WkbType t1 = g1.wkbType();
if ( t1 != Qgis::WKBLineString && t1 != Qgis::WKBLineString25D )
diff --git a/src/analysis/vector/qgstransectsample.h b/src/analysis/vector/qgstransectsample.h
index c0e0c0463e2..5bf3d31e9ae 100644
--- a/src/analysis/vector/qgstransectsample.h
+++ b/src/analysis/vector/qgstransectsample.h
@@ -48,11 +48,10 @@ class ANALYSIS_EXPORT QgsTransectSample
private:
QgsTransectSample(); //default constructor forbidden
- QgsGeometry* findBaselineGeometry( const QVariant& strataId );
+ QgsGeometry findBaselineGeometry( const QVariant& strataId );
/** Returns true if another transect is within the specified minimum distance*/
- static bool otherTransectWithinDistance( QgsGeometry* geom, double minDistLayerUnit, double minDistance, QgsSpatialIndex& sIndex, const QMap< QgsFeatureId, QgsGeometry* >&
- lineFeatureMap, QgsDistanceArea& da );
+ static bool otherTransectWithinDistance( QgsGeometry* geom, double minDistLayerUnit, double minDistance, QgsSpatialIndex& sIndex, const QMap& lineFeatureMap, QgsDistanceArea& da );
QgsVectorLayer* mStrataLayer;
QString mStrataIdAttribute;
@@ -83,7 +82,7 @@ class ANALYSIS_EXPORT QgsTransectSample
@param pt1 out: closest point on first geometry
@param pt2 out: closest point on secont geometry
@return true in case of success*/
- static bool closestSegmentPoints( QgsGeometry& g1, QgsGeometry& g2, double& dist, QgsPoint& pt1, QgsPoint& pt2 );
+ static bool closestSegmentPoints( const QgsGeometry& g1, const QgsGeometry& g2, double& dist, QgsPoint& pt1, QgsPoint& pt2 );
/** Returns a copy of the multiline element closest to a point (caller takes ownership)*/
static QgsGeometry* closestMultilineElement( const QgsPoint& pt, QgsGeometry* multiLine );
/** Returns clipped buffer line. Iteratively applies reduced tolerances if the result is not a single line
diff --git a/src/app/gps/qgsgpsinformationwidget.cpp b/src/app/gps/qgsgpsinformationwidget.cpp
index 754674f5bf3..d037a0422d0 100644
--- a/src/app/gps/qgsgpsinformationwidget.cpp
+++ b/src/app/gps/qgsgpsinformationwidget.cpp
@@ -827,8 +827,8 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked()
QgsWkbPtr wkbPtr( buf, size );
wkbPtr << ( char ) QgsApplication::endian() << Qgis::WKBPoint << x << y;
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( buf, size );
+ QgsGeometry g;
+ g.fromWkb( buf, size );
f->setGeometry( g );
QgsFeatureAction action( tr( "Feature added" ), *f, vlayer, -1, -1, this );
@@ -877,8 +877,8 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked()
wkbPtr << myPoint.x() << myPoint.y();
}
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( buf, size );
+ QgsGeometry g;
+ g.fromWkb( buf, size );
f->setGeometry( g );
}
else if ( layerWKBType == Qgis::WKBPolygon )
@@ -904,11 +904,13 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked()
wkbPtr << savePoint.x() << savePoint.y();
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( buf, size );
+ QgsGeometry g;
+ g.fromWkb( buf, size );
f->setGeometry( g );
- int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
+ QgsGeometry featGeom = *f->constGeometry();
+ int avoidIntersectionsReturn = featGeom.avoidIntersections();
+ f->setGeometry( featGeom );
if ( avoidIntersectionsReturn == 1 )
{
//not a polygon type. Impossible to get there
diff --git a/src/app/nodetool/qgsmaptoolnodetool.cpp b/src/app/nodetool/qgsmaptoolnodetool.cpp
index f6f937ab1cd..0f33120fa00 100644
--- a/src/app/nodetool/qgsmaptoolnodetool.cpp
+++ b/src/app/nodetool/qgsmaptoolnodetool.cpp
@@ -250,7 +250,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
}
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
- connect( vlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
+ connect( vlayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
mIsPoint = vlayer->geometryType() == Qgis::Point;
mNodeEditor = new QgsNodeEditor( vlayer, mSelectedFeature, mCanvas );
@@ -383,7 +383,7 @@ void QgsMapToolNodeTool::updateSelectFeature()
updateSelectFeature( *mSelectedFeature->geometry() );
}
-void QgsMapToolNodeTool::updateSelectFeature( QgsGeometry &geom )
+void QgsMapToolNodeTool::updateSelectFeature( const QgsGeometry &geom )
{
delete mSelectRubberBand;
@@ -419,7 +419,7 @@ void QgsMapToolNodeTool::selectedFeatureDestroyed()
cleanTool( false );
}
-void QgsMapToolNodeTool::geometryChanged( QgsFeatureId fid, QgsGeometry &geom )
+void QgsMapToolNodeTool::geometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
{
QSettings settings;
bool ghostLine = settings.value( "/qgis/digitizing/line_ghost", false ).toBool();
diff --git a/src/app/nodetool/qgsmaptoolnodetool.h b/src/app/nodetool/qgsmaptoolnodetool.h
index e3c6fcf8e87..4fc3858943f 100644
--- a/src/app/nodetool/qgsmaptoolnodetool.h
+++ b/src/app/nodetool/qgsmaptoolnodetool.h
@@ -53,7 +53,7 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
/*
* the geometry for the selected feature has changed
*/
- void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
+ void geometryChanged( QgsFeatureId fid, const QgsGeometry& geom );
/*
* the current layer changed
@@ -84,7 +84,7 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
/**
* Update select feature rubber band using a certain geometry
*/
- void updateSelectFeature( QgsGeometry &geom );
+ void updateSelectFeature( const QgsGeometry &geom );
/**
* Deletes the rubber band pointers and clears mRubberBands
diff --git a/src/app/nodetool/qgsselectedfeature.cpp b/src/app/nodetool/qgsselectedfeature.cpp
index 345e71afb4e..217c0411f60 100644
--- a/src/app/nodetool/qgsselectedfeature.cpp
+++ b/src/app/nodetool/qgsselectedfeature.cpp
@@ -68,7 +68,7 @@ void QgsSelectedFeature::currentLayerChanged( QgsMapLayer *layer )
deleteLater();
}
-void QgsSelectedFeature::updateGeometry( QgsGeometry *geom )
+void QgsSelectedFeature::updateGeometry( const QgsGeometry *geom )
{
QgsDebugCall;
@@ -78,8 +78,8 @@ void QgsSelectedFeature::updateGeometry( QgsGeometry *geom )
{
QgsFeature f;
mVlayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureId ) ).nextFeature( f );
- if ( f.geometry() )
- mGeometry = new QgsGeometry( *f.geometry() );
+ if ( f.constGeometry() )
+ mGeometry = new QgsGeometry( *f.constGeometry() );
else
mGeometry = new QgsGeometry();
}
@@ -112,7 +112,7 @@ void QgsSelectedFeature::setSelectedFeature( QgsFeatureId featureId, QgsVectorLa
connect( canvas, SIGNAL( extentsChanged() ), this, SLOT( updateVertexMarkersPosition() ) );
// geometry was changed
- connect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
+ connect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
replaceVertexMap();
}
@@ -120,7 +120,7 @@ void QgsSelectedFeature::setSelectedFeature( QgsFeatureId featureId, QgsVectorLa
void QgsSelectedFeature::beforeRollBack()
{
QgsDebugCall;
- disconnect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
+ disconnect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
deleteVertexMap();
}
@@ -129,7 +129,7 @@ void QgsSelectedFeature::beginGeometryChange()
Q_ASSERT( !mChangingGeometry );
mChangingGeometry = true;
- disconnect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
+ disconnect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
}
void QgsSelectedFeature::endGeometryChange()
@@ -137,7 +137,7 @@ void QgsSelectedFeature::endGeometryChange()
Q_ASSERT( mChangingGeometry );
mChangingGeometry = false;
- connect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
+ connect( mVlayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
}
void QgsSelectedFeature::canvasLayersChanged()
@@ -151,7 +151,7 @@ void QgsSelectedFeature::featureDeleted( QgsFeatureId fid )
deleteLater();
}
-void QgsSelectedFeature::geometryChanged( QgsFeatureId fid, QgsGeometry &geom )
+void QgsSelectedFeature::geometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
{
QgsDebugCall;
diff --git a/src/app/nodetool/qgsselectedfeature.h b/src/app/nodetool/qgsselectedfeature.h
index 6d226149bbb..14f5d635bbd 100644
--- a/src/app/nodetool/qgsselectedfeature.h
+++ b/src/app/nodetool/qgsselectedfeature.h
@@ -160,7 +160,7 @@ class QgsSelectedFeature: public QObject
/*
* the geometry of a feature from the layer was changed - might be the selected
*/
- void geometryChanged( QgsFeatureId, QgsGeometry & );
+ void geometryChanged( QgsFeatureId, const QgsGeometry& );
/*
* the current layer changed - destroy
@@ -192,7 +192,7 @@ class QgsSelectedFeature: public QObject
* Updates stored geometry to actual one loaded from layer
* (or already available geometry)
*/
- void updateGeometry( QgsGeometry *geom );
+ void updateGeometry( const QgsGeometry* geom );
/**
* Validates the geometry
diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp
index 3ff93c31caf..ad3e239a573 100644
--- a/src/app/qgisapp.cpp
+++ b/src/app/qgisapp.cpp
@@ -6358,20 +6358,18 @@ void QgisApp::deletePart()
mMapCanvas->setMapTool( mMapTools.mDeletePart );
}
-QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool& canceled )
+QgsGeometry QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool& canceled )
{
canceled = false;
if ( !vl || featureList.size() < 2 )
{
- return nullptr;
+ return QgsGeometry();
}
- QgsGeometry* unionGeom = featureList[0].geometry();
- QgsGeometry* backupPtr = nullptr; //pointer to delete intermediate results
- if ( !unionGeom )
- {
- return nullptr;
- }
+ if ( !featureList.at( 0 ).constGeometry() )
+ return QgsGeometry();
+
+ QgsGeometry unionGeom = *featureList[0].constGeometry();
QProgressDialog progress( tr( "Merging features..." ), tr( "Abort" ), 0, featureList.size(), this );
progress.setWindowModality( Qt::WindowModal );
@@ -6382,34 +6380,29 @@ QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
{
if ( progress.wasCanceled() )
{
- delete unionGeom;
QApplication::restoreOverrideCursor();
canceled = true;
- return nullptr;
+ return QgsGeometry();
}
progress.setValue( i );
- QgsGeometry* currentGeom = featureList[i].geometry();
- if ( currentGeom )
+ QgsGeometry currentGeom = *featureList[i].constGeometry();
+ if ( !currentGeom.isEmpty() )
{
- backupPtr = unionGeom;
- unionGeom = unionGeom->combine( currentGeom );
- if ( i > 1 ) //delete previous intermediate results
- {
- delete backupPtr;
- backupPtr = nullptr;
- }
- if ( !unionGeom )
+ QgsGeometry* result = unionGeom.combine( ¤tGeom );
+ unionGeom = *result;
+ delete result;
+ if ( unionGeom.isEmpty() )
{
QApplication::restoreOverrideCursor();
- return nullptr;
+ return QgsGeometry();
}
}
}
//convert unionGeom to a multipart geometry in case it is necessary to match the layer type
- if ( Qgis::isMultiType( vl->wkbType() ) && !unionGeom->isMultipart() )
+ if ( Qgis::isMultiType( vl->wkbType() ) && !unionGeom.isMultipart() )
{
- unionGeom->convertToMultiType();
+ unionGeom.convertToMultiType();
}
QApplication::restoreOverrideCursor();
@@ -6975,8 +6968,8 @@ void QgisApp::mergeSelectedFeatures()
QgsFeatureIds featureIds = vl->selectedFeaturesIds();
QgsFeatureList featureList = vl->selectedFeatures(); //get QList
bool canceled;
- QgsGeometry* unionGeom = unionGeometries( vl, featureList, canceled );
- if ( !unionGeom )
+ QgsGeometry unionGeom = unionGeometries( vl, featureList, canceled );
+ if ( unionGeom.isEmpty() )
{
if ( !canceled )
{
@@ -6992,7 +6985,6 @@ void QgisApp::mergeSelectedFeatures()
QgsMergeAttributesDialog d( featureList, vl, mapCanvas() );
if ( d.exec() == QDialog::Rejected )
{
- delete unionGeom;
return;
}
@@ -7004,18 +6996,16 @@ void QgisApp::mergeSelectedFeatures()
tr( "Not enough features selected" ),
tr( "The merge tool requires at least two selected features" ),
QgsMessageBar::WARNING );
- delete unionGeom;
return;
}
//if the user changed the feature selection in the merge dialog, we need to repeat the union and check the type
if ( featureIds.size() != featureIdsAfter.size() )
{
- delete unionGeom;
bool canceled;
QgsFeatureList featureListAfter = vl->selectedFeatures();
unionGeom = unionGeometries( vl, featureListAfter, canceled );
- if ( !unionGeom )
+ if ( unionGeom.isEmpty() )
{
if ( !canceled )
{
@@ -7393,10 +7383,13 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
featureIt = features.erase( featureIt );
continue;
}
- featureIt->setGeometry( newGeometry );
+ featureIt->setGeometry( *newGeometry );
+ delete newGeometry;
}
// avoid intersection if enabled in digitize settings
- featureIt->geometry()->avoidIntersections();
+ QgsGeometry g = *featureIt->constGeometry();
+ g.avoidIntersections();
+ featureIt->setGeometry( g );
}
++featureIt;
@@ -7582,12 +7575,14 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
if ( Qgis::singleType( wkbType ) != Qgis::singleType( type ) )
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
if ( Qgis::isMultiType( wkbType ) && Qgis::isSingleType( type ) )
{
- feature.geometry()->convertToMultiType();
+ QgsGeometry g = *feature.constGeometry();
+ g.convertToMultiType();
+ feature.setGeometry( g );
}
}
if ( ! layer->addFeatures( features, false ) || !layer->commitChanges() )
diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h
index 8b9f63869ee..18b2ca41e17 100644
--- a/src/app/qgisapp.h
+++ b/src/app/qgisapp.h
@@ -1415,8 +1415,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! check to see if file is dirty and if so, prompt the user th save it
bool saveDirty();
/** Helper function to union several geometries together (used in function mergeSelectedFeatures)
- @return 0 in case of error or if canceled */
- QgsGeometry* unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool &canceled );
+ @return empty geometry in case of error or if canceled */
+ QgsGeometry unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool &canceled );
/** Deletes all the composer objects and clears mPrintComposers*/
void deletePrintComposers();
diff --git a/src/app/qgsattributetabledialog.cpp b/src/app/qgsattributetabledialog.cpp
index 62643682455..ce2af6142a3 100644
--- a/src/app/qgsattributetabledialog.cpp
+++ b/src/app/qgsattributetabledialog.cpp
@@ -142,7 +142,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
QgsGeometry *g = QgsGeometry::fromRect( extent );
mRubberBand = new QgsRubberBand( mc, Qgis::Polygon );
- mRubberBand->setToGeometry( g, theLayer );
+ mRubberBand->setToGeometry( *g, theLayer );
delete g;
mActionShowAllFilter->setText( tr( "Show All Features In Initial Canvas Extent" ) );
diff --git a/src/app/qgsclipboard.cpp b/src/app/qgsclipboard.cpp
index d65555ff407..794139aecf4 100644
--- a/src/app/qgsclipboard.cpp
+++ b/src/app/qgsclipboard.cpp
@@ -196,7 +196,8 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString& string, const Q
if ( !fields.isEmpty() )
feature.setFields( fields, true );
- feature.setGeometry( geometry );
+ feature.setGeometry( *geometry );
+ delete geometry;
features.append( feature );
}
@@ -269,7 +270,9 @@ QgsFeatureList QgsClipboard::transformedCopyOf( const QgsCoordinateReferenceSyst
QgsDebugMsg( "transforming clipboard." );
for ( QgsFeatureList::iterator iter = featureList.begin(); iter != featureList.end(); ++iter )
{
- iter->geometry()->transform( ct );
+ QgsGeometry g = *iter->constGeometry();
+ g.transform( ct );
+ iter->setGeometry( g );
}
return featureList;
diff --git a/src/app/qgsfieldcalculator.cpp b/src/app/qgsfieldcalculator.cpp
index b2d5f4f39ea..70696c109ab 100644
--- a/src/app/qgsfieldcalculator.cpp
+++ b/src/app/qgsfieldcalculator.cpp
@@ -296,7 +296,7 @@ void QgsFieldCalculator::accept()
if ( value.canConvert< QgsGeometry >() )
{
QgsGeometry geom = value.value< QgsGeometry >();
- mVectorLayer->changeGeometry( feature.id(), &geom );
+ mVectorLayer->changeGeometry( feature.id(), geom );
}
}
else
diff --git a/src/app/qgsmaptooladdfeature.cpp b/src/app/qgsmaptooladdfeature.cpp
index 9590ff33478..5b71548fedc 100644
--- a/src/app/qgsmaptooladdfeature.cpp
+++ b/src/app/qgsmaptooladdfeature.cpp
@@ -165,7 +165,8 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
g = QgsGeometry::fromPoint( savePoint );
}
- f.setGeometry( g );
+ f.setGeometry( *g );
+ delete g;
f.setValid( true );
addFeature( vlayer, &f, false );
@@ -253,7 +254,9 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
if ( mode() == CaptureLine )
{
- f->setGeometry( new QgsGeometry( curveToAdd ) );
+ QgsGeometry* g = new QgsGeometry( curveToAdd );
+ f->setGeometry( *g );
+ delete g;
}
else
{
@@ -267,9 +270,13 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
poly = new QgsPolygonV2();
}
poly->setExteriorRing( curveToAdd );
- f->setGeometry( new QgsGeometry( poly ) );
+ QgsGeometry* g = new QgsGeometry( poly );
+ f->setGeometry( *g );
+ delete g;
- int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
+ QgsGeometry featGeom = *f->constGeometry();
+ int avoidIntersectionsReturn = featGeom.avoidIntersections();
+ f->setGeometry( featGeom );
if ( avoidIntersectionsReturn == 1 )
{
//not a polygon type. Impossible to get there
diff --git a/src/app/qgsmaptooldeletepart.cpp b/src/app/qgsmaptooldeletepart.cpp
index 8b875b4bcf3..e3e75319872 100644
--- a/src/app/qgsmaptooldeletepart.cpp
+++ b/src/app/qgsmaptooldeletepart.cpp
@@ -78,7 +78,7 @@ void QgsMapToolDeletePart::canvasPressEvent( QgsMapMouseEvent* e )
{
mRubberBand = createRubberBand( vlayer->geometryType() );
- mRubberBand->setToGeometry( geomPart, vlayer );
+ mRubberBand->setToGeometry( *geomPart, vlayer );
mRubberBand->show();
}
@@ -102,9 +102,9 @@ void QgsMapToolDeletePart::canvasReleaseEvent( QgsMapMouseEvent* e )
QgsFeature f;
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mPressedFid ) ).nextFeature( f );
- QgsGeometry* g = f.geometry();
+ QgsGeometry g = *f.constGeometry();
- if ( g->deletePart( mPressedPartNum ) )
+ if ( g.deletePart( mPressedPartNum ) )
{
vlayer->beginEditCommand( tr( "Part of multipart feature deleted" ) );
vlayer->changeGeometry( f.id(), g );
diff --git a/src/app/qgsmaptooldeletering.cpp b/src/app/qgsmaptooldeletering.cpp
index f188dffcf19..cbee8328f32 100644
--- a/src/app/qgsmaptooldeletering.cpp
+++ b/src/app/qgsmaptooldeletering.cpp
@@ -89,7 +89,7 @@ void QgsMapToolDeleteRing::canvasPressEvent( QgsMapMouseEvent* e )
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mPressedFid ) ).nextFeature( f );
mRubberBand = createRubberBand( vlayer->geometryType() );
- mRubberBand->setToGeometry( ringGeom, vlayer );
+ mRubberBand->setToGeometry( *ringGeom, vlayer );
mRubberBand->show();
}
@@ -108,12 +108,11 @@ void QgsMapToolDeleteRing::canvasReleaseEvent( QgsMapMouseEvent* e )
return;
QgsFeature f;
- QgsGeometry* g;
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mPressedFid ) ).nextFeature( f );
- g = f.geometry();
- if ( g->deleteRing( mPressedRingNum, mPressedPartNum ) )
+ QgsGeometry g = *f.constGeometry();
+ if ( g.deleteRing( mPressedRingNum, mPressedPartNum ) )
{
vlayer->beginEditCommand( tr( "Ring deleted" ) );
vlayer->changeGeometry( mPressedFid, g );
@@ -194,8 +193,8 @@ void QgsMapToolDeleteRing::deleteRing( QgsFeatureId fId, int beforeVertexNr, Qgs
else
return;
- QgsGeometry* editableGeom = f.geometry();
- if ( editableGeom->deleteRing( ringNum, partNum ) )
+ QgsGeometry editableGeom = *f.constGeometry();
+ if ( editableGeom.deleteRing( ringNum, partNum ) )
{
vlayer->beginEditCommand( tr( "Ring deleted" ) );
vlayer->changeGeometry( fId, editableGeom );
diff --git a/src/app/qgsmaptoolfillring.cpp b/src/app/qgsmaptoolfillring.cpp
index 1b75308fcc6..319494d9bd2 100644
--- a/src/app/qgsmaptoolfillring.cpp
+++ b/src/app/qgsmaptoolfillring.cpp
@@ -147,7 +147,9 @@ void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
//create QgsFeature with wkb representation
QgsFeature* ft = new QgsFeature( vlayer->fields(), 0 );
- ft->setGeometry( QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() ) );
+ QgsGeometry* g = QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() );
+ ft->setGeometry( *g );
+ delete g;
ft->setAttributes( f.attributes() );
bool res = false;
diff --git a/src/app/qgsmaptoollabel.cpp b/src/app/qgsmaptoollabel.cpp
index 5c5c41173a0..cdbfd02d87e 100644
--- a/src/app/qgsmaptoollabel.cpp
+++ b/src/app/qgsmaptoollabel.cpp
@@ -94,7 +94,7 @@ void QgsMapToolLabel::createRubberBands()
int a = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt();
mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() );
mFeatureRubberBand->setColor( QColor( r, g, b, a ) );
- mFeatureRubberBand->setToGeometry( geom, vlayer );
+ mFeatureRubberBand->setToGeometry( *geom, vlayer );
mFeatureRubberBand->show();
}
}
@@ -115,7 +115,7 @@ void QgsMapToolLabel::createRubberBands()
QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint );
mFixPointRubberBand = new QgsRubberBand( mCanvas, Qgis::Line );
mFixPointRubberBand->setColor( QColor( 0, 0, 255, 65 ) );
- mFixPointRubberBand->setToGeometry( pointGeom, vlayer );
+ mFixPointRubberBand->setToGeometry( *pointGeom, vlayer );
mFixPointRubberBand->show();
delete pointGeom;
}
diff --git a/src/app/qgsmaptoolmovefeature.cpp b/src/app/qgsmaptoolmovefeature.cpp
index 1c89d3bdbba..78c63c8fe7c 100644
--- a/src/app/qgsmaptoolmovefeature.cpp
+++ b/src/app/qgsmaptoolmovefeature.cpp
@@ -118,7 +118,7 @@ void QgsMapToolMoveFeature::canvasPressEvent( QgsMapMouseEvent* e )
mMovedFeatures << cf.id(); //todo: take the closest feature, not the first one...
mRubberBand = createRubberBand( vlayer->geometryType() );
- mRubberBand->setToGeometry( cf.constGeometry(), vlayer );
+ mRubberBand->setToGeometry( *cf.constGeometry(), vlayer );
}
else
{
@@ -130,7 +130,7 @@ void QgsMapToolMoveFeature::canvasPressEvent( QgsMapMouseEvent* e )
while ( it.nextFeature( feat ) )
{
- mRubberBand->addGeometry( feat.constGeometry(), vlayer );
+ mRubberBand->addGeometry( *feat.constGeometry(), vlayer );
}
}
diff --git a/src/app/qgsmaptooloffsetcurve.cpp b/src/app/qgsmaptooloffsetcurve.cpp
index 9ab84ac3533..1fcf89d3cac 100644
--- a/src/app/qgsmaptooloffsetcurve.cpp
+++ b/src/app/qgsmaptooloffsetcurve.cpp
@@ -70,7 +70,7 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QgsMapMouseEvent* e )
return;
}
- if ( !mOriginalGeometry )
+ if ( mOriginalGeometry.isEmpty() )
{
deleteRubberBandAndGeometry();
mGeometryModified = false;
@@ -121,7 +121,7 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QgsMapMouseEvent* e )
}
}
- if ( !mOriginalGeometry )
+ if ( mOriginalGeometry.isEmpty() )
{
emit messageEmitted( tr( "Could not find a nearby feature in any vector layer." ) );
}
@@ -160,7 +160,7 @@ void QgsMapToolOffsetCurve::applyOffset()
bool editOk;
if ( mSourceLayerId == layer->id() && !mForceCopy )
{
- editOk = layer->changeGeometry( mModifiedFeature, &mModifiedGeometry );
+ editOk = layer->changeGeometry( mModifiedFeature, mModifiedGeometry );
}
else
{
@@ -205,7 +205,7 @@ void QgsMapToolOffsetCurve::canvasMoveEvent( QgsMapMouseEvent* e )
delete mSnapVertexMarker;
mSnapVertexMarker = nullptr;
- if ( !mOriginalGeometry || !mRubberBand )
+ if ( mOriginalGeometry.isEmpty() || !mRubberBand )
{
return;
}
@@ -240,7 +240,7 @@ void QgsMapToolOffsetCurve::canvasMoveEvent( QgsMapMouseEvent* e )
QgsPoint minDistPoint;
int beforeVertex;
double leftOf;
- double offset = sqrt( mOriginalGeometry->closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex, &leftOf ) );
+ double offset = sqrt( mOriginalGeometry.closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex, &leftOf ) );
if ( offset == 0.0 )
{
return;
@@ -261,11 +261,11 @@ void QgsMapToolOffsetCurve::canvasMoveEvent( QgsMapMouseEvent* e )
}
}
-QgsGeometry* QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer* vl, const QgsPointLocator::Match& match, QgsFeature& snappedFeature )
+QgsGeometry QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer* vl, const QgsPointLocator::Match& match, QgsFeature& snappedFeature )
{
if ( !vl )
{
- return nullptr;
+ return QgsGeometry();
}
mMultiPartGeometry = false;
@@ -274,10 +274,8 @@ QgsGeometry* QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer* vl, co
if ( vl == currentVectorLayer() && !mForceCopy )
{
- Q_NOWARN_DEPRECATED_PUSH
//don't consider selected geometries, only the snap result
- return convertToSingleLine( snappedFeature.geometryAndOwnership(), partVertexNr, mMultiPartGeometry );
- Q_NOWARN_DEPRECATED_POP
+ return convertToSingleLine( snappedFeature.constGeometry() ? *snappedFeature.constGeometry() : QgsGeometry(), partVertexNr, mMultiPartGeometry );
}
else //snapped to a background layer
{
@@ -292,33 +290,27 @@ QgsGeometry* QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer* vl, co
const QgsFeatureIds& selection = vl->selectedFeaturesIds();
if ( selection.size() < 1 || !selection.contains( match.featureId() ) )
{
- Q_NOWARN_DEPRECATED_PUSH
- return convertToSingleLine( snappedFeature.geometryAndOwnership(), partVertexNr, mMultiPartGeometry );
- Q_NOWARN_DEPRECATED_POP
+ return convertToSingleLine( snappedFeature.constGeometry() ? *snappedFeature.constGeometry() : QgsGeometry(), partVertexNr, mMultiPartGeometry );
}
else
{
//merge together if several features
QgsFeatureList selectedFeatures = vl->selectedFeatures();
QgsFeatureList::iterator selIt = selectedFeatures.begin();
- Q_NOWARN_DEPRECATED_PUSH
- QgsGeometry* geom = selIt->geometryAndOwnership();
- Q_NOWARN_DEPRECATED_POP
+ QgsGeometry geom = selIt->constGeometry() ? *selIt->constGeometry() : QgsGeometry();
++selIt;
for ( ; selIt != selectedFeatures.end(); ++selIt )
{
- QgsGeometry* combined = geom->combine( selIt->constGeometry() );
- delete geom;
- geom = combined;
+ QgsGeometry* combined = geom.combine( selIt->constGeometry() );
+ geom = *combined;
+ delete combined;
}
//if multitype, return only the snapped to geometry
- if ( geom->isMultipart() )
+ if ( geom.isMultipart() )
{
- delete geom;
- Q_NOWARN_DEPRECATED_PUSH
- return convertToSingleLine( snappedFeature.geometryAndOwnership(), match.vertexIndex(), mMultiPartGeometry );
- Q_NOWARN_DEPRECATED_POP
+ return convertToSingleLine( snappedFeature.constGeometry() ? *snappedFeature.constGeometry() : QgsGeometry(),
+ match.vertexIndex(), mMultiPartGeometry );
}
return geom;
@@ -365,8 +357,6 @@ void QgsMapToolOffsetCurve::deleteRubberBandAndGeometry()
{
delete mRubberBand;
mRubberBand = nullptr;
- delete mOriginalGeometry;
- mOriginalGeometry = nullptr;
}
void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
@@ -374,7 +364,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
// need at least geos 3.3 for OffsetCurve tool
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
- if ( !mRubberBand || !mOriginalGeometry )
+ if ( !mRubberBand || mOriginalGeometry.isEmpty() )
{
return;
}
@@ -385,7 +375,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
return;
}
- QgsGeometry geomCopy( *mOriginalGeometry );
+ QgsGeometry geomCopy( mOriginalGeometry );
const GEOSGeometry* geosGeom = geomCopy.asGeos();
if ( geosGeom )
{
@@ -411,7 +401,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
if ( offsetGeom )
{
mModifiedGeometry.fromGeos( offsetGeom );
- mRubberBand->setToGeometry( &mModifiedGeometry, sourceLayer );
+ mRubberBand->setToGeometry( mModifiedGeometry, sourceLayer );
}
}
#else //GEOS_VERSION>=3.3
@@ -419,11 +409,11 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
#endif //GEOS_VERSION>=3.3
}
-QgsGeometry* QgsMapToolOffsetCurve::linestringFromPolygon( const QgsGeometry* featureGeom, int vertex )
+QgsGeometry QgsMapToolOffsetCurve::linestringFromPolygon( const QgsGeometry* featureGeom, int vertex )
{
if ( !featureGeom )
{
- return nullptr;
+ return QgsGeometry();
}
Qgis::WkbType geomType = featureGeom->wkbType();
@@ -442,7 +432,7 @@ QgsGeometry* QgsMapToolOffsetCurve::linestringFromPolygon( const QgsGeometry* fe
}
else
{
- return nullptr;
+ return QgsGeometry();
}
QgsMultiPolygon::const_iterator multiPolyIt = multiPoly.constBegin();
@@ -455,24 +445,27 @@ QgsGeometry* QgsMapToolOffsetCurve::linestringFromPolygon( const QgsGeometry* fe
if ( vertex < currentVertex )
{
//found, return ring
- return QgsGeometry::fromPolyline( *polyIt );
+ QgsGeometry* g = QgsGeometry::fromPolyline( *polyIt );
+ QgsGeometry result = *g;
+ delete g;
+ return result;
}
}
}
- return nullptr;
+ return QgsGeometry();
}
-QgsGeometry* QgsMapToolOffsetCurve::convertToSingleLine( QgsGeometry* geom, int vertex, bool& isMulti )
+QgsGeometry QgsMapToolOffsetCurve::convertToSingleLine( const QgsGeometry& geom, int vertex, bool& isMulti )
{
- if ( !geom )
+ if ( geom.isEmpty() )
{
- return nullptr;
+ return QgsGeometry();
}
isMulti = false;
- Qgis::WkbType geomType = geom->wkbType();
+ Qgis::WkbType geomType = geom.wkbType();
if ( geomType == Qgis::WKBLineString || geomType == Qgis::WKBLineString25D )
{
return geom;
@@ -482,7 +475,7 @@ QgsGeometry* QgsMapToolOffsetCurve::convertToSingleLine( QgsGeometry* geom, int
//search vertex
isMulti = true;
int currentVertex = 0;
- QgsMultiPolyline multiLine = geom->asMultiPolyline();
+ QgsMultiPolyline multiLine = geom.asMultiPolyline();
QgsMultiPolyline::const_iterator it = multiLine.constBegin();
for ( ; it != multiLine.constEnd(); ++it )
{
@@ -490,13 +483,11 @@ QgsGeometry* QgsMapToolOffsetCurve::convertToSingleLine( QgsGeometry* geom, int
if ( vertex < currentVertex )
{
QgsGeometry* g = QgsGeometry::fromPolyline( *it );
- delete geom;
- return g;
+ return *g;
}
}
}
- delete geom;
- return nullptr;
+ return QgsGeometry();
}
QgsGeometry* QgsMapToolOffsetCurve::convertToMultiLine( QgsGeometry* geom )
diff --git a/src/app/qgsmaptooloffsetcurve.h b/src/app/qgsmaptooloffsetcurve.h
index 198f5a35aa1..335190cc924 100644
--- a/src/app/qgsmaptooloffsetcurve.h
+++ b/src/app/qgsmaptooloffsetcurve.h
@@ -44,7 +44,7 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
/** Rubberband that shows the position of the offset curve*/
QgsRubberBand* mRubberBand;
/** Geometry to manipulate*/
- QgsGeometry* mOriginalGeometry;
+ QgsGeometry mOriginalGeometry;
/** Geometry after manipulation*/
QgsGeometry mModifiedGeometry;
/** ID of manipulated feature*/
@@ -63,14 +63,14 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
void deleteRubberBandAndGeometry();
- QgsGeometry* createOriginGeometry( QgsVectorLayer* vl, const QgsPointLocator::Match& match, QgsFeature& snappedFeature );
+ QgsGeometry createOriginGeometry( QgsVectorLayer* vl, const QgsPointLocator::Match& match, QgsFeature& snappedFeature );
void createDistanceWidget();
void deleteDistanceWidget();
void setOffsetForRubberBand( double offset );
/** Creates a linestring from the polygon ring containing the snapped vertex. Caller takes ownership of the created object*/
- QgsGeometry* linestringFromPolygon( const QgsGeometry *featureGeom, int vertex );
+ QgsGeometry linestringFromPolygon( const QgsGeometry *featureGeom, int vertex );
/** Returns a single line from a multiline (or does nothing if geometry is already a single line). Deletes the input geometry*/
- QgsGeometry* convertToSingleLine( QgsGeometry* geom, int vertex, bool& isMulti );
+ QgsGeometry convertToSingleLine( const QgsGeometry& geom, int vertex, bool& isMulti );
/** Converts offset line back to a multiline if necessary*/
QgsGeometry* convertToMultiLine( QgsGeometry* geom );
};
diff --git a/src/app/qgsmaptoolreshape.cpp b/src/app/qgsmaptoolreshape.cpp
index a3f003151b5..a6ef40f2f84 100644
--- a/src/app/qgsmaptoolreshape.cpp
+++ b/src/app/qgsmaptoolreshape.cpp
@@ -95,10 +95,10 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
//query geometry
//call geometry->reshape(mCaptureList)
//register changed geometry in vector layer
- QgsGeometry* geom = f.geometry();
- if ( geom )
+ QgsGeometry geom = f.constGeometry() ? *f.constGeometry() : QgsGeometry();
+ if ( !geom.isEmpty() )
{
- reshapeReturn = geom->reshapeGeometry( points() );
+ reshapeReturn = geom.reshapeGeometry( points() );
if ( reshapeReturn == 0 )
{
//avoid intersections on polygon layers
@@ -108,7 +108,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
QMap > ignoreFeatures;
ignoreFeatures.insert( vlayer, vlayer->allFeatureIds() );
- if ( geom->avoidIntersections( ignoreFeatures ) != 0 )
+ if ( geom.avoidIntersections( ignoreFeatures ) != 0 )
{
emit messageEmitted( tr( "An error was reported during intersection removal" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
@@ -116,7 +116,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
return;
}
- if ( geom->isGeosEmpty() ) //intersection removal might have removed the whole geometry
+ if ( geom.isGeosEmpty() ) //intersection removal might have removed the whole geometry
{
emit messageEmitted( tr( "The feature cannot be reshaped because the resulting geometry is empty" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
diff --git a/src/app/qgsmaptoolrotatefeature.cpp b/src/app/qgsmaptoolrotatefeature.cpp
index 9c0e57d20b6..16b9f0b3711 100644
--- a/src/app/qgsmaptoolrotatefeature.cpp
+++ b/src/app/qgsmaptoolrotatefeature.cpp
@@ -278,7 +278,7 @@ void QgsMapToolRotateFeature::canvasReleaseEvent( QgsMapMouseEvent* e )
mRotatedFeatures << cf.id(); //todo: take the closest feature, not the first one...
mRubberBand = createRubberBand( vlayer->geometryType() );
- mRubberBand->setToGeometry( cf.constGeometry(), vlayer );
+ mRubberBand->setToGeometry( *cf.constGeometry(), vlayer );
}
else
{
@@ -290,7 +290,7 @@ void QgsMapToolRotateFeature::canvasReleaseEvent( QgsMapMouseEvent* e )
QgsFeatureIterator it = vlayer->selectedFeaturesIterator();
while ( it.nextFeature( feat ) )
{
- mRubberBand->addGeometry( feat.constGeometry(), vlayer );
+ mRubberBand->addGeometry( *feat.constGeometry(), vlayer );
}
}
diff --git a/src/app/qgsmaptoolsimplify.cpp b/src/app/qgsmaptoolsimplify.cpp
index 7d3194e3ac0..9df12c34606 100644
--- a/src/app/qgsmaptoolsimplify.cpp
+++ b/src/app/qgsmaptoolsimplify.cpp
@@ -120,7 +120,7 @@ void QgsMapToolSimplify::updateSimplificationPreview()
if ( QgsGeometry* g = fSel.constGeometry()->simplify( layerTolerance ) )
{
mReducedVertexCount += vertexCount( g );
- mRubberBands.at( i )->setToGeometry( g, vl );
+ mRubberBands.at( i )->setToGeometry( *g, vl );
delete g;
}
else
@@ -181,7 +181,7 @@ void QgsMapToolSimplify::storeSimplified()
{
if ( QgsGeometry* g = feat.constGeometry()->simplify( layerTolerance ) )
{
- vlayer->changeGeometry( feat.id(), g );
+ vlayer->changeGeometry( feat.id(), *g );
delete g;
}
}
diff --git a/src/app/qgsmergeattributesdialog.cpp b/src/app/qgsmergeattributesdialog.cpp
index 3925e981467..d4f98fd6a79 100644
--- a/src/app/qgsmergeattributesdialog.cpp
+++ b/src/app/qgsmergeattributesdialog.cpp
@@ -513,7 +513,7 @@ void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureI
mSelectionRubberBand->setColor( QColor( 255, 0, 0, 65 ) );
QgsFeature featureToSelect;
mVectorLayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( featureToSelect );
- mSelectionRubberBand->setToGeometry( featureToSelect.constGeometry(), mVectorLayer );
+ mSelectionRubberBand->setToGeometry( featureToSelect.constGeometry() ? *featureToSelect.constGeometry() : QgsGeometry(), mVectorLayer );
}
QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
diff --git a/src/core/qgsfeature.cpp b/src/core/qgsfeature.cpp
index c71ff8241f1..ee8b4762fc0 100644
--- a/src/core/qgsfeature.cpp
+++ b/src/core/qgsfeature.cpp
@@ -84,14 +84,6 @@ const QgsGeometry* QgsFeature::constGeometry() const
return d->geometry;
}
-QgsGeometry *QgsFeature::geometryAndOwnership()
-{
- d.detach();
- d->ownsGeometry = false;
-
- return d->geometry;
-}
-
/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests in testqgsfeature.cpp.
@@ -123,58 +115,32 @@ void QgsFeature::setAttributes( const QgsAttributes &attrs )
void QgsFeature::setGeometry( const QgsGeometry& geom )
{
- setGeometry( new QgsGeometry( geom ) );
+ d.detach();
+
+ if ( geom.isEmpty() )
+ {
+ delete d->geometry;
+ d->geometry = nullptr;
+ }
+ else
+ {
+ QgsGeometry* newGeom = new QgsGeometry( geom );
+ delete d->geometry;
+ d->geometry = newGeom;
+ }
}
void QgsFeature::setGeometry( QgsGeometry* geom )
{
- // we do a little bit of trickery here to avoid an unnecessary deep copy
- // of the existing geometry by the detach function
- // (since we are replacing the geometry anyway)
-
- //first, store the old ownsGeometry status
- QgsFeaturePrivate* old_d = d.data();
- bool ownedGeom = d->ownsGeometry;
-
- //then set owns geometry to false before the detach, so that the deep copy
- //is not made
- d->ownsGeometry = false;
- d.detach();
-
- //restore ownsGeometry setting if a detach was made
- if ( old_d != d.data() )
- {
- old_d->ownsGeometry = ownedGeom;
- }
- else if ( ownedGeom )
- {
- delete d->geometry;
- }
-
- d->geometry = geom;
- d->ownsGeometry = true;
}
+
/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests in testqgsfeature.cpp.
* See details in QEP #17
****************************************************************************/
-/** Set the pointer to the feature geometry
-*/
-void QgsFeature::setGeometryAndOwnership( unsigned char *geom, int length )
-{
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( geom, length );
- setGeometry( g );
-}
-
-void QgsFeature::setFields( const QgsFields* fields, bool init )
-{
- setFields( *fields, init );
-}
-
void QgsFeature::setFields( const QgsFields &fields, bool init )
{
d.detach();
@@ -314,10 +280,10 @@ QDataStream& operator<<( QDataStream& out, const QgsFeature& feature )
QDataStream& operator>>( QDataStream& in, QgsFeature& feature )
{
QgsFeatureId id;
- QgsGeometry* geometry = new QgsGeometry();
+ QgsGeometry geometry;
bool valid;
QgsAttributes attr;
- in >> id >> attr >> *geometry >> valid;
+ in >> id >> attr >> geometry >> valid;
feature.setFeatureId( id );
feature.setGeometry( geometry );
feature.setAttributes( attr );
diff --git a/src/core/qgsfeature.h b/src/core/qgsfeature.h
index 5da3b62ae89..ecd83222cd4 100644
--- a/src/core/qgsfeature.h
+++ b/src/core/qgsfeature.h
@@ -100,7 +100,6 @@ typedef int QgsFeatureId;
#define STRING_TO_FID(str) (str).toLong()
#endif
-
// key = field index, value = field value
typedef QMap QgsAttributeMap;
@@ -281,10 +280,9 @@ class CORE_EXPORT QgsFeature
*
* @returns pointer to feature's geometry
* @see constGeometry
- * @see geometryAndOwnership
* @see setGeometry
*/
- QgsGeometry* geometry();
+ Q_DECL_DEPRECATED QgsGeometry* geometry();
/** Gets a const pointer to the geometry object associated with this feature. If the geometry
* is not going to be modified than this method is preferable to the non-const
@@ -292,29 +290,17 @@ class CORE_EXPORT QgsFeature
* @note this is a temporary method for 2.x release cycle. Will be removed in QGIS 3.0.
* @returns const pointer to feature's geometry
* @see geometry
- * @see geometryAndOwnership
* @see setGeometry
* @note added in QGIS 2.9
* @note will be removed in QGIS 3.0
*/
const QgsGeometry* constGeometry() const;
- /** Get the geometry object associated with this feature, and transfer ownership of the
- * geometry to the caller. The caller assumes responsibility for the QgsGeometry*'s destruction.
- * @returns pointer to feature's geometry
- * @see geometry
- * @see setGeometry
- * @deprecated use constGeometry() instead
- */
- Q_DECL_DEPRECATED QgsGeometry *geometryAndOwnership();
-
/** Set this feature's geometry from another QgsGeometry object. This method performs a deep copy
* of the geometry.
* @param geom new feature geometry
* @see geometry
* @see constGeometry
- * @see geometryAndOwnership
- * @see setGeometryAndOwnership
*/
void setGeometry( const QgsGeometry& geom );
@@ -324,32 +310,8 @@ class CORE_EXPORT QgsFeature
* @note not available in python bindings
* @see geometry
* @see constGeometry
- * @see geometryAndOwnership
- * @see setGeometryAndOwnership
*/
- void setGeometry( QgsGeometry* geom );
-
- /** Set this feature's geometry from WKB. This feature assumes responsibility for destroying the
- * created geometry.
- * @param geom geometry as WKB
- * @param length size of WKB
- * @see setGeometry
- * @see geometry
- * @see constGeometry
- * @see geometryAndOwnership
- * @deprecated will be removed in QGIS 3.0
- */
- Q_DECL_DEPRECATED void setGeometryAndOwnership( unsigned char * geom, int length );
-
- /** Assign a field map with the feature to allow attribute access by attribute name.
- * @param fields The attribute fields which this feature holds
- * @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
- * C++: Defaults to false
- * Python: Defaults to true
- * @deprecated use setFields( const QgsFields& fields, bool initAttributes = false ) instead
- * @note not available in Python bindings
- */
- Q_DECL_DEPRECATED void setFields( const QgsFields* fields, bool initAttributes = false );
+ Q_DECL_DEPRECATED void setGeometry( QgsGeometry* geom );
/** Assign a field map with the feature to allow attribute access by attribute name.
* @param fields The attribute fields which this feature holds
diff --git a/src/core/qgsfeature_p.h b/src/core/qgsfeature_p.h
index ecc3e568315..01f975403fc 100644
--- a/src/core/qgsfeature_p.h
+++ b/src/core/qgsfeature_p.h
@@ -44,7 +44,6 @@ class QgsFeaturePrivate : public QSharedData
explicit QgsFeaturePrivate( QgsFeatureId id )
: fid( id )
, geometry( nullptr )
- , ownsGeometry( false )
, valid( false )
{
}
@@ -53,8 +52,7 @@ class QgsFeaturePrivate : public QSharedData
: QSharedData( other )
, fid( other.fid )
, attributes( other.attributes )
- , geometry( other.ownsGeometry && other.geometry ? new QgsGeometry( *other.geometry ) : other.geometry )
- , ownsGeometry( other.ownsGeometry )
+ , geometry( other.geometry ? new QgsGeometry( *other.geometry ) : nullptr )
, valid( other.valid )
, fields( other.fields )
{
@@ -62,8 +60,7 @@ class QgsFeaturePrivate : public QSharedData
~QgsFeaturePrivate()
{
- if ( ownsGeometry )
- delete geometry;
+ delete geometry;
}
//! feature id
@@ -78,11 +75,6 @@ class QgsFeaturePrivate : public QSharedData
*/
QgsGeometry *geometry;
- /** Indicator if the mGeometry is owned by this QgsFeature.
- If so, this QgsFeature takes responsibility for the mGeometry's destruction.
- */
- bool ownsGeometry;
-
//! Flag to indicate if this feature is valid
bool valid;
diff --git a/src/core/qgsgml.cpp b/src/core/qgsgml.cpp
index ee068de73d9..3c97ede379b 100644
--- a/src/core/qgsgml.cpp
+++ b/src/core/qgsgml.cpp
@@ -863,11 +863,11 @@ void QgsGmlStreamingParser::endElement( const XML_Char* el )
#else
OGR_G_ExportToWkb( hGeom, wkbNDR, pabyBuffer );
#endif
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( pabyBuffer, wkbSize );
+ QgsGeometry g;
+ g.fromWkb( pabyBuffer, wkbSize );
if ( mInvertAxisOrientation )
{
- g->transform( QTransform( 0, 1, 1, 0, 0, 0 ) );
+ g.transform( QTransform( 0, 1, 1, 0, 0, 0 ) );
}
mCurrentFeature->setGeometry( g );
OGR_G_DestroyGeometry( hGeom );
@@ -933,18 +933,20 @@ void QgsGmlStreamingParser::endElement( const XML_Char* el )
memcmp( pszLocalName, mTypeNamePtr, mTypeName.size() ) == 0 ) )
{
Q_ASSERT( mCurrentFeature );
- if ( !mCurrentFeature->geometry() )
+ if ( !mCurrentFeature->constGeometry() )
{
if ( mCurrentWKB.size() > 0 )
{
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( mCurrentWKB, mCurrentWKB.size() );
+ QgsGeometry g;
+ g.fromWkb( mCurrentWKB, mCurrentWKB.size() );
mCurrentFeature->setGeometry( g );
mCurrentWKB = QgsWkbPtr( nullptr, 0 );
}
else if ( !mCurrentExtent.isEmpty() )
{
- mCurrentFeature->setGeometry( QgsGeometry::fromRect( mCurrentExtent ) );
+ QgsGeometry* featGeom = QgsGeometry::fromRect( mCurrentExtent );
+ mCurrentFeature->setGeometry( *featGeom );
+ delete featGeom;
}
}
mCurrentFeature->setValid( true );
diff --git a/src/core/qgsofflineediting.cpp b/src/core/qgsofflineediting.cpp
index db68d692bf0..d4d296684f9 100644
--- a/src/core/qgsofflineediting.cpp
+++ b/src/core/qgsofflineediting.cpp
@@ -835,7 +835,9 @@ void QgsOfflineEditing::applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlit
for ( int i = 0; i < values.size(); i++ )
{
QgsFeatureId fid = remoteFid( db, layerId, values.at( i ).fid );
- remoteLayer->changeGeometry( fid, QgsGeometry::fromWkt( values.at( i ).geom_wkt ) );
+ QgsGeometry* newGeom = QgsGeometry::fromWkt( values.at( i ).geom_wkt );
+ remoteLayer->changeGeometry( fid, *newGeom );
+ delete newGeom;
emit progressUpdated( i + 1 );
}
diff --git a/src/core/qgsogrutils.cpp b/src/core/qgsogrutils.cpp
index dddd007c089..24ddf12de3f 100644
--- a/src/core/qgsogrutils.cpp
+++ b/src/core/qgsogrutils.cpp
@@ -213,25 +213,25 @@ bool QgsOgrUtils::readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature& featur
OGRGeometryH geom = OGR_F_GetGeometryRef( ogrFet );
if ( !geom )
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
else
feature.setGeometry( ogrGeometryToQgsGeometry( geom ) );
return true;
}
-QgsGeometry* QgsOgrUtils::ogrGeometryToQgsGeometry( OGRGeometryH geom )
+QgsGeometry QgsOgrUtils::ogrGeometryToQgsGeometry( OGRGeometryH geom )
{
if ( !geom )
- return nullptr;
+ return QgsGeometry();
// get the wkb representation
int memorySize = OGR_G_WkbSize( geom );
unsigned char *wkb = new unsigned char[memorySize];
OGR_G_ExportToWkb( geom, ( OGRwkbByteOrder ) QgsApplication::endian(), wkb );
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( wkb, memorySize );
+ QgsGeometry g;
+ g.fromWkb( wkb, memorySize );
return g;
}
diff --git a/src/core/qgsogrutils.h b/src/core/qgsogrutils.h
index 003ac664ee0..247ae0171ee 100644
--- a/src/core/qgsogrutils.h
+++ b/src/core/qgsogrutils.h
@@ -81,10 +81,11 @@ class CORE_EXPORT QgsOgrUtils
/** Converts an OGR geometry representation to a QgsGeometry object
* @param geom OGR geometry handle
- * @returns new QgsGeometry object, if conversion was successful
+ * @returns QgsGeometry object. If conversion was not successful the geometry
+ * will be empty.
* @see readOgrFeatureGeometry()
*/
- static QgsGeometry* ogrGeometryToQgsGeometry( OGRGeometryH geom );
+ static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
/** Attempts to parse a string representing a collection of features using OGR. For example, this method can be
* used to convert a GeoJSON encoded collection to a list of QgsFeatures.
diff --git a/src/core/qgspointlocator.cpp b/src/core/qgspointlocator.cpp
index 0e30798c6e1..30a3cdd5d10 100644
--- a/src/core/qgspointlocator.cpp
+++ b/src/core/qgspointlocator.cpp
@@ -627,7 +627,7 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateRefe
connect( mLayer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( onFeatureAdded( QgsFeatureId ) ) );
connect( mLayer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( onFeatureDeleted( QgsFeatureId ) ) );
- connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, const QgsGeometry& ) ) );
}
@@ -707,7 +707,9 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
{
try
{
- f.geometry()->transform( mTransform );
+ QgsGeometry transformedGeometry = *f.constGeometry();
+ transformedGeometry.transform( mTransform );
+ f.setGeometry( transformedGeometry );
}
catch ( const QgsException& e )
{
@@ -786,7 +788,9 @@ void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )
{
try
{
- f.geometry()->transform( mTransform );
+ QgsGeometry transformedGeom = *f.constGeometry();
+ transformedGeom.transform( mTransform );
+ f.setGeometry( transformedGeom );
}
catch ( const QgsException& e )
{
@@ -822,7 +826,7 @@ void QgsPointLocator::onFeatureDeleted( QgsFeatureId fid )
}
}
-void QgsPointLocator::onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom )
+void QgsPointLocator::onGeometryChanged( QgsFeatureId fid, const QgsGeometry& geom )
{
Q_UNUSED( geom );
onFeatureDeleted( fid );
diff --git a/src/core/qgspointlocator.h b/src/core/qgspointlocator.h
index c1054b6c87b..f19fa8075b1 100644
--- a/src/core/qgspointlocator.h
+++ b/src/core/qgspointlocator.h
@@ -212,7 +212,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
private slots:
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
- void onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom );
+ void onGeometryChanged( QgsFeatureId fid, const QgsGeometry& geom );
private:
/** Storage manager */
diff --git a/src/core/qgstracer.cpp b/src/core/qgstracer.cpp
index 0569f424602..0f94752251d 100644
--- a/src/core/qgstracer.cpp
+++ b/src/core/qgstracer.cpp
@@ -501,7 +501,9 @@ bool QgsTracer::initGraph()
{
try
{
- f.geometry()->transform( ct );
+ QgsGeometry transformedGeom = *f.constGeometry();
+ transformedGeom.transform( ct );
+ f.setGeometry( transformedGeom );
}
catch ( QgsCsException& )
{
@@ -586,7 +588,7 @@ void QgsTracer::setLayers( const QList& layers )
{
disconnect( layer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( onFeatureAdded( QgsFeatureId ) ) );
disconnect( layer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( onFeatureDeleted( QgsFeatureId ) ) );
- disconnect( layer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ disconnect( layer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, const QgsGeometry& ) ) );
disconnect( layer, SIGNAL( destroyed( QObject* ) ), this, SLOT( onLayerDestroyed( QObject* ) ) );
}
@@ -596,7 +598,7 @@ void QgsTracer::setLayers( const QList& layers )
{
connect( layer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( onFeatureAdded( QgsFeatureId ) ) );
connect( layer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( onFeatureDeleted( QgsFeatureId ) ) );
- connect( layer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ connect( layer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, const QgsGeometry& ) ) );
connect( layer, SIGNAL( destroyed( QObject* ) ), this, SLOT( onLayerDestroyed( QObject* ) ) );
}
@@ -660,7 +662,7 @@ void QgsTracer::onFeatureDeleted( QgsFeatureId fid )
invalidateGraph();
}
-void QgsTracer::onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom )
+void QgsTracer::onGeometryChanged( QgsFeatureId fid, const QgsGeometry& geom )
{
Q_UNUSED( fid );
Q_UNUSED( geom );
diff --git a/src/core/qgstracer.h b/src/core/qgstracer.h
index d4b020ae87b..a43490a354d 100644
--- a/src/core/qgstracer.h
+++ b/src/core/qgstracer.h
@@ -114,7 +114,7 @@ class CORE_EXPORT QgsTracer : public QObject
private slots:
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
- void onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom );
+ void onGeometryChanged( QgsFeatureId fid, const QgsGeometry& geom );
void onLayerDestroyed( QObject* obj );
private:
diff --git a/src/core/qgsvectorfilewriter.cpp b/src/core/qgsvectorfilewriter.cpp
index 2f64b489fd9..979f0928338 100644
--- a/src/core/qgsvectorfilewriter.cpp
+++ b/src/core/qgsvectorfilewriter.cpp
@@ -1843,7 +1843,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature, QgsFeatureRendererV2*
return true;
}
-OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
+OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature& feature )
{
QgsLocaleNumC l; // Make sure the decimal delimiter is a dot
Q_UNUSED( l );
@@ -1966,16 +1966,16 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
if ( feature.constGeometry() && !feature.constGeometry()->isEmpty() )
{
// build geometry from WKB
- QgsGeometry* geom = feature.geometry();
+ QgsGeometry geom = *feature.constGeometry();
// 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.geometry()->wkbType() ) != QgsWKBTypes::flatType( mWkbType ) &&
+ QgsWKBTypes::flatType( geom.geometry()->wkbType() ) == QgsWKBTypes::flatType( QgsWKBTypes::singleType( mWkbType ) ) )
{
- geom->convertToMultiType();
+ geom.convertToMultiType();
}
- if ( geom->geometry()->wkbType() != mWkbType )
+ if ( geom.geometry()->wkbType() != mWkbType )
{
OGRGeometryH mGeom2 = nullptr;
@@ -1987,10 +1987,10 @@ OGRFeatureH QgsVectorFileWriter::createFeature( 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.geometry()->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.geometry()->wkbType() - QgsWKBTypes::PointZ + QgsWKBTypes::Point25D );
mGeom2 = createEmptyGeometry( wkbType25d );
}
}
@@ -2005,7 +2005,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( 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.geometry()->wkbType() );
}
if ( !mGeom2 )
@@ -2018,7 +2018,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
return nullptr;
}
- OGRErr err = OGR_G_ImportFromWkb( mGeom2, const_cast( geom->asWkb() ), static_cast< int >( geom->wkbSize() ) );
+ OGRErr err = OGR_G_ImportFromWkb( mGeom2, const_cast( geom.asWkb() ), static_cast< int >( geom.wkbSize() ) );
if ( err != OGRERR_NONE )
{
mErrorMessage = QObject::tr( "Feature geometry not imported (OGR error: %1)" )
@@ -2034,7 +2034,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
}
else // wkb type matches
{
- OGRErr err = OGR_G_ImportFromWkb( mGeom, const_cast( geom->asWkb() ), static_cast< int >( geom->wkbSize() ) );
+ OGRErr err = OGR_G_ImportFromWkb( mGeom, const_cast( geom.asWkb() ), static_cast< int >( geom.wkbSize() ) );
if ( err != OGRERR_NONE )
{
mErrorMessage = QObject::tr( "Feature geometry not imported (OGR error: %1)" )
@@ -2346,9 +2346,11 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
{
try
{
- if ( fet.geometry() )
+ if ( fet.constGeometry() )
{
- fet.geometry()->transform( ct );
+ QgsGeometry g = *fet.constGeometry();
+ g.transform( ct );
+ fet.setGeometry( g );
}
}
catch ( QgsCsException &e )
@@ -2668,9 +2670,11 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
{
try
{
- if ( fet.geometry() )
+ if ( fet.constGeometry() )
{
- fet.geometry()->transform( ct );
+ QgsGeometry g = *fet.constGeometry();
+ g.transform( ct );
+ fet.setGeometry( g );
}
}
catch ( QgsCsException &e )
diff --git a/src/core/qgsvectorfilewriter.h b/src/core/qgsvectorfilewriter.h
index b081c44da6c..d1cd1126b43 100644
--- a/src/core/qgsvectorfilewriter.h
+++ b/src/core/qgsvectorfilewriter.h
@@ -444,7 +444,7 @@ class CORE_EXPORT QgsVectorFileWriter
static QMap initMetaData();
void createSymbolLayerTable( QgsVectorLayer* vl, const QgsCoordinateTransform& ct, OGRDataSourceH ds );
- OGRFeatureH createFeature( QgsFeature& feature );
+ OGRFeatureH createFeature( const QgsFeature& feature );
bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
/** Writes features considering symbol level order*/
diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp
index 2410aa327c3..1e2fee9fc30 100644
--- a/src/core/qgsvectorlayer.cpp
+++ b/src/core/qgsvectorlayer.cpp
@@ -1078,7 +1078,7 @@ bool QgsVectorLayer::updateFeature( QgsFeature &f )
if ( f.constGeometry() && current.constGeometry() && f.constGeometry() != current.constGeometry() && !f.constGeometry()->isGeosEqual( *current.constGeometry() ) )
{
- if ( !changeGeometry( f.id(), f.geometry() ) )
+ if ( !changeGeometry( f.id(), *f.constGeometry() ) )
{
QgsDebugMsg( QString( "geometry of feature %1 could not be changed." ).arg( f.id() ) );
return false;
@@ -1482,7 +1482,7 @@ bool QgsVectorLayer::startEditing()
//connect( mEditBuffer, SIGNAL( layerModified() ), this, SLOT( triggerRepaint() ) ); // TODO[MD]: works well?
connect( mEditBuffer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SIGNAL( featureAdded( QgsFeatureId ) ) );
connect( mEditBuffer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( onFeatureDeleted( QgsFeatureId ) ) );
- connect( mEditBuffer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ connect( mEditBuffer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ) );
connect( mEditBuffer, SIGNAL( attributeValueChanged( QgsFeatureId, int, QVariant ) ), this, SIGNAL( attributeValueChanged( QgsFeatureId, int, QVariant ) ) );
connect( mEditBuffer, SIGNAL( attributeAdded( int ) ), this, SIGNAL( attributeAdded( int ) ) );
connect( mEditBuffer, SIGNAL( attributeDeleted( int ) ), this, SIGNAL( attributeDeleted( int ) ) );
@@ -2153,7 +2153,7 @@ bool QgsVectorLayer::writeSld( QDomNode& node, QDomDocument& doc, QString& error
}
-bool QgsVectorLayer::changeGeometry( QgsFeatureId fid, QgsGeometry* geom )
+bool QgsVectorLayer::changeGeometry( QgsFeatureId fid, const QgsGeometry& geom )
{
if ( !mEditBuffer || !mDataProvider )
{
diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h
index f218f21d70d..02eaff55984 100644
--- a/src/core/qgsvectorlayer.h
+++ b/src/core/qgsvectorlayer.h
@@ -1307,7 +1307,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
bool setReadOnly( bool readonly = true );
/** Change feature's geometry */
- bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
+ bool changeGeometry( QgsFeatureId fid, const QgsGeometry& geom );
/**
* Changes an attribute value (but does not commit it)
@@ -2022,7 +2022,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @param fid The id of the changed feature
* @param geometry The new geometry
*/
- void geometryChanged( QgsFeatureId fid, QgsGeometry& geometry );
+ void geometryChanged( QgsFeatureId fid, const QgsGeometry& geometry );
/** This signal is emitted, when attributes are deleted from the provider */
void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
diff --git a/src/core/qgsvectorlayercache.cpp b/src/core/qgsvectorlayercache.cpp
index ed3698e84e1..a82307ab458 100644
--- a/src/core/qgsvectorlayercache.cpp
+++ b/src/core/qgsvectorlayercache.cpp
@@ -61,11 +61,11 @@ void QgsVectorLayerCache::setCacheGeometry( bool cacheGeometry )
mCacheGeometry = cacheGeometry && mLayer->hasGeometryType();
if ( cacheGeometry )
{
- connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), SLOT( geometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), SLOT( geometryChanged( QgsFeatureId, const QgsGeometry& ) ) );
}
else
{
- disconnect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ disconnect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SLOT( geometryChanged( QgsFeatureId, connect QgsGeometry& ) ) );
}
}
@@ -244,7 +244,7 @@ void QgsVectorLayerCache::attributeDeleted( int field )
}
}
-void QgsVectorLayerCache::geometryChanged( QgsFeatureId fid, QgsGeometry& geom )
+void QgsVectorLayerCache::geometryChanged( QgsFeatureId fid, const QgsGeometry& geom )
{
QgsCachedFeature* cachedFeat = mCache[ fid ];
diff --git a/src/core/qgsvectorlayercache.h b/src/core/qgsvectorlayercache.h
index ade8c12929a..cd5e48ab1e1 100644
--- a/src/core/qgsvectorlayercache.h
+++ b/src/core/qgsvectorlayercache.h
@@ -302,7 +302,7 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
void onFeatureAdded( QgsFeatureId fid );
void attributeAdded( int field );
void attributeDeleted( int field );
- void geometryChanged( QgsFeatureId fid, QgsGeometry& geom );
+ void geometryChanged( QgsFeatureId fid, const QgsGeometry& geom );
void layerDeleted();
void invalidate();
diff --git a/src/core/qgsvectorlayereditbuffer.cpp b/src/core/qgsvectorlayereditbuffer.cpp
index 4b393a856a7..bc7ff6b1dc9 100644
--- a/src/core/qgsvectorlayereditbuffer.cpp
+++ b/src/core/qgsvectorlayereditbuffer.cpp
@@ -179,7 +179,7 @@ bool QgsVectorLayerEditBuffer::deleteFeatures( const QgsFeatureIds& fids )
}
-bool QgsVectorLayerEditBuffer::changeGeometry( QgsFeatureId fid, QgsGeometry* geom )
+bool QgsVectorLayerEditBuffer::changeGeometry( QgsFeatureId fid, QgsGeometry geom )
{
if ( !L->hasGeometryType() )
{
diff --git a/src/core/qgsvectorlayereditbuffer.h b/src/core/qgsvectorlayereditbuffer.h
index a1bf045861f..448ad17b59b 100644
--- a/src/core/qgsvectorlayereditbuffer.h
+++ b/src/core/qgsvectorlayereditbuffer.h
@@ -58,7 +58,7 @@ class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
virtual bool deleteFeatures( const QgsFeatureIds& fid );
/** Change feature's geometry */
- virtual bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
+ virtual bool changeGeometry( QgsFeatureId fid, QgsGeometry geom );
/** Changed an attribute value (but does not commit it) */
virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
@@ -172,7 +172,7 @@ class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
void featureAdded( QgsFeatureId fid );
void featureDeleted( QgsFeatureId fid );
- void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
+ void geometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
void attributeAdded( int idx );
void attributeDeleted( int idx );
diff --git a/src/core/qgsvectorlayereditpassthrough.cpp b/src/core/qgsvectorlayereditpassthrough.cpp
index fa028eb1da9..88e813b592c 100644
--- a/src/core/qgsvectorlayereditpassthrough.cpp
+++ b/src/core/qgsvectorlayereditpassthrough.cpp
@@ -81,13 +81,13 @@ bool QgsVectorLayerEditPassthrough::deleteFeatures( const QgsFeatureIds& fids )
return false;
}
-bool QgsVectorLayerEditPassthrough::changeGeometry( QgsFeatureId fid, QgsGeometry* geom )
+bool QgsVectorLayerEditPassthrough::changeGeometry( QgsFeatureId fid, QgsGeometry geom )
{
QgsGeometryMap geomMap;
- geomMap.insert( fid, *geom );
+ geomMap.insert( fid, geom );
if ( L->dataProvider()->changeGeometryValues( geomMap ) )
{
- emit geometryChanged( fid, *geom );
+ emit geometryChanged( fid, geom );
mModified = true;
return true;
}
diff --git a/src/core/qgsvectorlayereditpassthrough.h b/src/core/qgsvectorlayereditpassthrough.h
index cb6baac57fe..21568a1d6ee 100644
--- a/src/core/qgsvectorlayereditpassthrough.h
+++ b/src/core/qgsvectorlayereditpassthrough.h
@@ -32,7 +32,7 @@ class CORE_EXPORT QgsVectorLayerEditPassthrough : public QgsVectorLayerEditBuffe
bool addFeatures( QgsFeatureList& features ) override;
bool deleteFeature( QgsFeatureId fid ) override;
bool deleteFeatures( const QgsFeatureIds& fids ) override;
- bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom ) override;
+ bool changeGeometry( QgsFeatureId fid, QgsGeometry geom ) override;
bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() ) override;
bool addAttribute( const QgsField &field ) override;
bool deleteAttribute( int attr ) override;
diff --git a/src/core/qgsvectorlayereditutils.cpp b/src/core/qgsvectorlayereditutils.cpp
index b5997fbc52d..7b33dfe1330 100644
--- a/src/core/qgsvectorlayereditutils.cpp
+++ b/src/core/qgsvectorlayereditutils.cpp
@@ -51,7 +51,7 @@ bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atF
geometry.insertVertex( x, y, beforeVertex );
- L->editBuffer()->changeGeometry( atFeatureId, &geometry );
+ L->editBuffer()->changeGeometry( atFeatureId, geometry );
return true;
}
@@ -80,7 +80,7 @@ bool QgsVectorLayerEditUtils::moveVertex( const QgsPointV2& p, QgsFeatureId atFe
geometry.moveVertex( p, atVertex );
- L->editBuffer()->changeGeometry( atFeatureId, &geometry );
+ L->editBuffer()->changeGeometry( atFeatureId, geometry );
return true;
}
@@ -116,7 +116,7 @@ QgsVectorLayer::EditResult QgsVectorLayerEditUtils::deleteVertexV2( QgsFeatureId
geometry.setGeometry( nullptr );
}
- L->editBuffer()->changeGeometry( featureId, &geometry );
+ L->editBuffer()->changeGeometry( featureId, geometry );
return !geometry.isEmpty() ? QgsVectorLayer::Success : QgsVectorLayer::EmptyGeometry;
}
@@ -164,10 +164,12 @@ int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring, const QgsFeatureIds& tar
continue;
//add ring takes ownership of ring, and deletes it if there's an error
- addRingReturnCode = f.geometry()->addRing( static_cast< QgsCurveV2* >( ring->clone() ) );
+ QgsGeometry g = *f.constGeometry();
+
+ addRingReturnCode = g.addRing( static_cast< QgsCurveV2* >( ring->clone() ) );
if ( addRingReturnCode == 0 )
{
- L->editBuffer()->changeGeometry( f.id(), f.geometry() );
+ L->editBuffer()->changeGeometry( f.id(), g );
if ( modifiedFeatureId )
*modifiedFeatureId = f.id();
@@ -211,7 +213,7 @@ int QgsVectorLayerEditUtils::addPart( const QgsPointSequenceV2 &points, QgsFeatu
}
else
{
- geometry = *f.geometry();
+ geometry = *f.constGeometry();
}
}
@@ -224,7 +226,7 @@ int QgsVectorLayerEditUtils::addPart( const QgsPointSequenceV2 &points, QgsFeatu
//convert back to single part if required by layer
geometry.convertToSingleType();
}
- L->editBuffer()->changeGeometry( featureId, &geometry );
+ L->editBuffer()->changeGeometry( featureId, geometry );
}
return errorCode;
}
@@ -250,7 +252,7 @@ int QgsVectorLayerEditUtils::addPart( QgsCurveV2* ring, QgsFeatureId featureId )
}
else
{
- geometry = *f.geometry();
+ geometry = *f.constGeometry();
}
}
@@ -263,7 +265,7 @@ int QgsVectorLayerEditUtils::addPart( QgsCurveV2* ring, QgsFeatureId featureId )
//convert back to single part if required by layer
geometry.convertToSingleType();
}
- L->editBuffer()->changeGeometry( featureId, &geometry );
+ L->editBuffer()->changeGeometry( featureId, geometry );
}
return errorCode;
}
@@ -288,7 +290,7 @@ int QgsVectorLayerEditUtils::translateFeature( QgsFeatureId featureId, double dx
int errorCode = geometry.translate( dx, dy );
if ( errorCode == 0 )
{
- L->editBuffer()->changeGeometry( featureId, &geometry );
+ L->editBuffer()->changeGeometry( featureId, geometry );
}
return errorCode;
}
@@ -366,18 +368,19 @@ int QgsVectorLayerEditUtils::splitFeatures( const QList& splitLine, bo
QList newGeometries;
QList topologyTestPoints;
QgsGeometry* newGeometry = nullptr;
- splitFunctionReturn = feat.geometry()->splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
+ QgsGeometry featureGeom = *feat.constGeometry();
+ splitFunctionReturn = featureGeom.splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
if ( splitFunctionReturn == 0 )
{
//change this geometry
- L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
+ L->editBuffer()->changeGeometry( feat.id(), featureGeom );
//insert new features
for ( int i = 0; i < newGeometries.size(); ++i )
{
newGeometry = newGeometries.at( i );
QgsFeature newFeature;
- newFeature.setGeometry( newGeometry );
+ newFeature.setGeometry( *newGeometry );
//use default value where possible for primary key (e.g. autoincrement),
//and use the value from the original (split) feature if not primary key
@@ -497,16 +500,17 @@ int QgsVectorLayerEditUtils::splitParts( const QList& splitLine, bool
{
QList newGeometries;
QList topologyTestPoints;
- splitFunctionReturn = feat.geometry()->splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
+ QgsGeometry featureGeom = *feat.constGeometry();
+ splitFunctionReturn = featureGeom.splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
if ( splitFunctionReturn == 0 )
{
//add new parts
if ( !newGeometries.isEmpty() )
- feat.geometry()->convertToMultiType();
+ featureGeom.convertToMultiType();
for ( int i = 0; i < newGeometries.size(); ++i )
{
- addPartRet = feat.geometry()->addPart( newGeometries.at( i ) );
+ addPartRet = featureGeom.addPart( newGeometries.at( i ) );
if ( addPartRet )
break;
}
@@ -516,7 +520,7 @@ int QgsVectorLayerEditUtils::splitParts( const QList& splitLine, bool
if ( !addPartRet )
{
- L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
+ L->editBuffer()->changeGeometry( feat.id(), featureGeom );
}
else
{
@@ -536,7 +540,7 @@ int QgsVectorLayerEditUtils::splitParts( const QList& splitLine, bool
break;
}
}
- L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
+ L->editBuffer()->changeGeometry( feat.id(), featureGeom );
if ( topologicalEditing )
{
diff --git a/src/core/qgsvectorlayerfeatureiterator.cpp b/src/core/qgsvectorlayerfeatureiterator.cpp
index dfa60fe5dc5..5379af06706 100644
--- a/src/core/qgsvectorlayerfeatureiterator.cpp
+++ b/src/core/qgsvectorlayerfeatureiterator.cpp
@@ -361,7 +361,7 @@ void QgsVectorLayerFeatureIterator::useAddedFeature( const QgsFeature& src, QgsF
if ( src.constGeometry() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
- f.setGeometry( new QgsGeometry( *src.constGeometry() ) );
+ f.setGeometry( *src.constGeometry() );
}
// TODO[MD]: if subset set just some attributes
diff --git a/src/core/qgsvectorlayerimport.cpp b/src/core/qgsvectorlayerimport.cpp
index e0aca027422..d4af900e708 100644
--- a/src/core/qgsvectorlayerimport.cpp
+++ b/src/core/qgsvectorlayerimport.cpp
@@ -370,7 +370,9 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
{
if ( fet.constGeometry() )
{
- fet.geometry()->transform( ct );
+ QgsGeometry g = *fet.constGeometry();
+ g.transform( ct );
+ fet.setGeometry( g );
}
}
catch ( QgsCsException &e )
diff --git a/src/core/qgsvectorlayerundocommand.cpp b/src/core/qgsvectorlayerundocommand.cpp
index ab6c64312a2..5da096194f9 100644
--- a/src/core/qgsvectorlayerundocommand.cpp
+++ b/src/core/qgsvectorlayerundocommand.cpp
@@ -112,25 +112,24 @@ void QgsVectorLayerUndoCommandDeleteFeature::redo()
-QgsVectorLayerUndoCommandChangeGeometry::QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, QgsGeometry* newGeom )
+QgsVectorLayerUndoCommandChangeGeometry::QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, QgsGeometry newGeom )
: QgsVectorLayerUndoCommand( buffer )
, mFid( fid )
+ , mNewGeom( newGeom )
{
if ( FID_IS_NEW( mFid ) )
{
QgsFeatureMap::const_iterator it = mBuffer->mAddedFeatures.constFind( mFid );
Q_ASSERT( it != mBuffer->mAddedFeatures.constEnd() );
- mOldGeom = ( it.value().constGeometry() ? new QgsGeometry( *it.value().constGeometry() ) : nullptr );
+ mOldGeom = ( it.value().constGeometry() ? QgsGeometry( *it.value().constGeometry() ) : QgsGeometry() );
}
else
{
bool changedAlready = mBuffer->mChangedGeometries.contains( mFid );
QgsGeometry geom;
bool cachedGeom = cache()->geometry( mFid, geom );
- mOldGeom = ( changedAlready && cachedGeom ) ? new QgsGeometry( geom ) : nullptr;
+ mOldGeom = ( changedAlready && cachedGeom ) ? geom : QgsGeometry();
}
-
- mNewGeom = new QgsGeometry( *newGeom );
}
int QgsVectorLayerUndoCommandChangeGeometry::id() const
@@ -150,17 +149,14 @@ bool QgsVectorLayerUndoCommandChangeGeometry::mergeWith( const QUndoCommand *oth
if ( merge->mFid != mFid )
return false;
- delete mNewGeom;
mNewGeom = merge->mNewGeom;
- merge->mNewGeom = nullptr;
+ merge->mNewGeom = QgsGeometry();
return true;
}
QgsVectorLayerUndoCommandChangeGeometry::~QgsVectorLayerUndoCommandChangeGeometry()
{
- delete mOldGeom;
- delete mNewGeom;
}
void QgsVectorLayerUndoCommandChangeGeometry::undo()
@@ -170,16 +166,16 @@ void QgsVectorLayerUndoCommandChangeGeometry::undo()
// modify added features
QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.find( mFid );
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
- it.value().setGeometry( *mOldGeom );
+ it.value().setGeometry( mOldGeom );
- cache()->cacheGeometry( mFid, *mOldGeom );
- emit mBuffer->geometryChanged( mFid, *mOldGeom );
+ cache()->cacheGeometry( mFid, mOldGeom );
+ emit mBuffer->geometryChanged( mFid, mOldGeom );
}
else
{
// existing feature
- if ( !mOldGeom )
+ if ( mOldGeom.isEmpty() )
{
mBuffer->mChangedGeometries.remove( mFid );
@@ -187,14 +183,14 @@ void QgsVectorLayerUndoCommandChangeGeometry::undo()
if ( layer()->getFeatures( QgsFeatureRequest().setFilterFid( mFid ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) && f.constGeometry() )
{
cache()->cacheGeometry( mFid, *f.constGeometry() );
- emit mBuffer->geometryChanged( mFid, *f.geometry() );
+ emit mBuffer->geometryChanged( mFid, *f.constGeometry() );
}
}
else
{
- mBuffer->mChangedGeometries[mFid] = *mOldGeom;
- cache()->cacheGeometry( mFid, *mOldGeom );
- emit mBuffer->geometryChanged( mFid, *mOldGeom );
+ mBuffer->mChangedGeometries[mFid] = mOldGeom;
+ cache()->cacheGeometry( mFid, mOldGeom );
+ emit mBuffer->geometryChanged( mFid, mOldGeom );
}
}
@@ -207,14 +203,14 @@ void QgsVectorLayerUndoCommandChangeGeometry::redo()
// modify added features
QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.find( mFid );
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
- it.value().setGeometry( *mNewGeom );
+ it.value().setGeometry( mNewGeom );
}
else
{
- mBuffer->mChangedGeometries[ mFid ] = *mNewGeom;
+ mBuffer->mChangedGeometries[ mFid ] = mNewGeom;
}
- cache()->cacheGeometry( mFid, *mNewGeom );
- emit mBuffer->geometryChanged( mFid, *mNewGeom );
+ cache()->cacheGeometry( mFid, mNewGeom );
+ emit mBuffer->geometryChanged( mFid, mNewGeom );
}
diff --git a/src/core/qgsvectorlayerundocommand.h b/src/core/qgsvectorlayerundocommand.h
index 9c16b9c6bbe..d2a4c2bb7bb 100644
--- a/src/core/qgsvectorlayerundocommand.h
+++ b/src/core/qgsvectorlayerundocommand.h
@@ -121,7 +121,7 @@ class CORE_EXPORT QgsVectorLayerUndoCommandChangeGeometry : public QgsVectorLaye
* @param fid feature ID of feature to modify geometry of
* @param newGeom new geometry for feature
*/
- QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, QgsGeometry* newGeom );
+ QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, QgsGeometry newGeom );
~QgsVectorLayerUndoCommandChangeGeometry();
virtual void undo() override;
@@ -131,8 +131,8 @@ class CORE_EXPORT QgsVectorLayerUndoCommandChangeGeometry : public QgsVectorLaye
private:
QgsFeatureId mFid;
- QgsGeometry* mOldGeom;
- mutable QgsGeometry* mNewGeom;
+ QgsGeometry mOldGeom;
+ mutable QgsGeometry mNewGeom;
};
diff --git a/src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp b/src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
index be938acea8a..b3f6496fd7a 100644
--- a/src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
+++ b/src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
@@ -269,7 +269,8 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
// compute the difference with the extent
QScopedPointer rect( QgsGeometry::fromPolygon( mExtentPolygon ) );
QgsGeometry *final = rect->difference( const_cast( unioned.data() ) );
- feat.setGeometry( final );
+ feat.setGeometry( *final );
+ delete final;
}
else
{
@@ -318,7 +319,9 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
}
}
}
- feat.setGeometry( QgsGeometry::fromMultiPolygon( finalMulti ) );
+ QgsGeometry* featGeom = QgsGeometry::fromMultiPolygon( finalMulti );
+ feat.setGeometry( *featGeom );
+ delete featGeom;
}
if ( feat.constGeometry() )
{
@@ -342,7 +345,9 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
{
// empty feature with default attributes
QgsFeature feat( mFields );
- feat.setGeometry( QgsGeometry::fromPolygon( mExtentPolygon ) );
+ QgsGeometry* featGeom = QgsGeometry::fromPolygon( mExtentPolygon );
+ feat.setGeometry( *featGeom );
+ delete featGeom;
mSubRenderer->renderFeature( feat, mContext );
}
diff --git a/src/gui/qgshighlight.cpp b/src/gui/qgshighlight.cpp
index 203a1d0d0c0..f7fdc3f22b4 100644
--- a/src/gui/qgshighlight.cpp
+++ b/src/gui/qgshighlight.cpp
@@ -94,7 +94,9 @@ void QgsHighlight::init()
}
else if ( mFeature.constGeometry() )
{
- mFeature.geometry()->transform( ct );
+ QgsGeometry g = *mFeature.constGeometry();
+ g.transform( ct );
+ mFeature.setGeometry( g );
}
}
}
diff --git a/src/gui/qgsmaptoolcapture.cpp b/src/gui/qgsmaptoolcapture.cpp
index 85fa2ff8b29..132d021e901 100644
--- a/src/gui/qgsmaptoolcapture.cpp
+++ b/src/gui/qgsmaptoolcapture.cpp
@@ -383,9 +383,9 @@ int QgsMapToolCapture::fetchLayerPoint( QgsPointLocator::Match match , QgsPointV
if ( fetched )
{
QgsVertexId vId;
- if ( !f.geometry()->vertexIdFromVertexNr( match.vertexIndex(), vId ) )
+ if ( !f.constGeometry()->vertexIdFromVertexNr( match.vertexIndex(), vId ) )
return 2;
- layerPoint = f.geometry()->geometry()->vertexAt( vId );
+ layerPoint = f.constGeometry()->geometry()->vertexAt( vId );
return 0;
}
else
diff --git a/src/gui/qgsrubberband.cpp b/src/gui/qgsrubberband.cpp
index 2c5c3ae1fc7..3d3d077ac9a 100644
--- a/src/gui/qgsrubberband.cpp
+++ b/src/gui/qgsrubberband.cpp
@@ -278,21 +278,21 @@ void QgsRubberBand::movePoint( int index, const QgsPoint& p, int geometryIndex )
update();
}
-void QgsRubberBand::setToGeometry( const QgsGeometry* geom, QgsVectorLayer* layer )
+void QgsRubberBand::setToGeometry( const QgsGeometry& geom, QgsVectorLayer* layer )
{
- if ( !geom )
+ if ( geom.isEmpty() )
{
reset( mGeometryType );
return;
}
- reset( geom->type() );
+ reset( geom.type() );
addGeometry( geom, layer );
}
-void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer )
+void QgsRubberBand::addGeometry( const QgsGeometry& geom, QgsVectorLayer* layer )
{
- if ( !geom )
+ if ( geom.isEmpty() )
{
return;
}
@@ -302,7 +302,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
int idx = mPoints.size();
- switch ( geom->wkbType() )
+ switch ( geom.wkbType() )
{
case Qgis::WKBPoint:
@@ -311,11 +311,11 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
QgsPoint pt;
if ( layer )
{
- pt = ms.layerToMapCoordinates( layer, geom->asPoint() );
+ pt = ms.layerToMapCoordinates( layer, geom.asPoint() );
}
else
{
- pt = geom->asPoint();
+ pt = geom.asPoint();
}
addPoint( pt, false, idx );
removeLastPoint( idx, false );
@@ -325,7 +325,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
case Qgis::WKBMultiPoint:
case Qgis::WKBMultiPoint25D:
{
- QgsMultiPoint mpt = geom->asMultiPoint();
+ QgsMultiPoint mpt = geom.asMultiPoint();
for ( int i = 0; i < mpt.size(); ++i, ++idx )
{
QgsPoint pt = mpt[i];
@@ -346,7 +346,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
case Qgis::WKBLineString:
case Qgis::WKBLineString25D:
{
- QgsPolyline line = geom->asPolyline();
+ QgsPolyline line = geom.asPolyline();
for ( int i = 0; i < line.count(); i++ )
{
if ( layer )
@@ -365,7 +365,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
case Qgis::WKBMultiLineString25D:
{
- QgsMultiPolyline mline = geom->asMultiPolyline();
+ QgsMultiPolyline mline = geom.asMultiPolyline();
for ( int i = 0; i < mline.size(); ++i, ++idx )
{
QgsPolyline line = mline[i];
@@ -393,7 +393,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
case Qgis::WKBPolygon:
case Qgis::WKBPolygon25D:
{
- QgsPolygon poly = geom->asPolygon();
+ QgsPolygon poly = geom.asPolygon();
QgsPolyline line = poly[0];
for ( int i = 0; i < line.count(); i++ )
{
@@ -413,7 +413,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer
case Qgis::WKBMultiPolygon25D:
{
- QgsMultiPolygon multipoly = geom->asMultiPolygon();
+ QgsMultiPolygon multipoly = geom.asMultiPolygon();
for ( int i = 0; i < multipoly.size(); ++i, ++idx )
{
QgsPolygon poly = multipoly[i];
diff --git a/src/gui/qgsrubberband.h b/src/gui/qgsrubberband.h
index f78a12bc245..10f512e34ae 100644
--- a/src/gui/qgsrubberband.h
+++ b/src/gui/qgsrubberband.h
@@ -197,7 +197,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
* @param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
- void setToGeometry( const QgsGeometry *geom, QgsVectorLayer* layer );
+ void setToGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
/**
* Sets this rubber band to a map canvas rectangle
@@ -216,7 +216,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
* @param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
- void addGeometry( const QgsGeometry *geom, QgsVectorLayer* layer );
+ void addGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
/**
* Adds translation to original coordinates (all in map coordinates)
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
index 22c2ad9b9ff..4f2f63ef9fb 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
@@ -28,7 +28,8 @@ void QgsGeometryAngleCheck::collectErrors( QList& errors
{
continue;
}
- const QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry g = *feature.constGeometry();
+ const QgsAbstractGeometryV2* geom = g.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
@@ -75,7 +76,8 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError* error, int method,
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geometry = feature.geometry()->geometry();
+ QgsGeometry g = *feature.constGeometry();
+ QgsAbstractGeometryV2* geometry = g.geometry();
QgsVertexId vidx = error->vidx();
// Check if point still exists
@@ -132,6 +134,7 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError* error, int method,
{
changes[error->featureId()].append( Change( ChangeNode, ChangeRemoved, QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) ) );
}
+ feature.setGeometry( g );
mFeaturePool->updateFeature( feature );
error->setFixed( method );
}
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
index f5b30050c80..b1b9ab74cbd 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
@@ -30,7 +30,8 @@ void QgsGeometryAreaCheck::collectErrors( QList& errors,
continue;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry g = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = g.geometry();
if ( dynamic_cast( geom ) )
{
QgsGeometryCollectionV2* multiGeom = static_cast( geom );
@@ -62,7 +63,8 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError* error, int method, i
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry g = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = g.geometry();
QgsVertexId vidx = error->vidx();
// Check if polygon still exists
@@ -126,17 +128,19 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( QgsFeature& feature, int partIdx,
QgsFeature mergeFeature;
int mergePartIdx = -1;
bool matchFound = false;
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry g = *feature.constGeometry();;
+ QgsAbstractGeometryV2* geom = g.geometry();
// Search for touching neighboring geometries
- Q_FOREACH ( QgsFeatureId testId, mFeaturePool->getIntersects( feature.geometry()->boundingBox() ) )
+ Q_FOREACH ( QgsFeatureId testId, mFeaturePool->getIntersects( g.boundingBox() ) )
{
QgsFeature testFeature;
if ( !mFeaturePool->get( testId, testFeature ) )
{
continue;
}
- QgsAbstractGeometryV2* testGeom = testFeature.geometry()->geometry();
+ QgsGeometry testFeatureGeom = *testFeature.constGeometry();
+ QgsAbstractGeometryV2* testGeom = testFeatureGeom.geometry();
for ( int testPartIdx = 0, nTestParts = testGeom->partCount(); testPartIdx < nTestParts; ++testPartIdx )
{
if ( testId == feature.id() && testPartIdx == partIdx )
@@ -191,7 +195,8 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( QgsFeature& feature, int partIdx,
}
// Merge geometries
- QgsAbstractGeometryV2* mergeGeom = mergeFeature.geometry()->geometry();
+ QgsGeometry mergeFeatureGeom = *mergeFeature.constGeometry();
+ QgsAbstractGeometryV2* mergeGeom = mergeFeatureGeom.geometry();
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* combinedGeom = geomEngine->combine( *QgsGeometryCheckerUtils::getGeomPart( geom, partIdx ), &errMsg );
delete geomEngine;
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
index 0bbfaf1cda1..38a9549ad96 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
@@ -77,9 +77,10 @@ QgsGeometryCheckError::~QgsGeometryCheckError()
QgsAbstractGeometryV2 *QgsGeometryCheckError::geometry()
{
QgsFeature f;
- if ( mCheck->getFeaturePool()->get( featureId(), f ) && f.geometry() )
+ if ( mCheck->getFeaturePool()->get( featureId(), f ) && f.constGeometry() )
{
- QgsAbstractGeometryV2* geom = f.geometry()->geometry();
+ QgsGeometry featureGeom = *f.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
return mVidx.part >= 0 ? QgsGeometryCheckerUtils::getGeomPart( geom, mVidx.part )->clone() : geom->clone();
}
return nullptr;
@@ -153,7 +154,8 @@ bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes& chan
void QgsGeometryCheck::replaceFeatureGeometryPart( QgsFeature& feature, int partIdx, QgsAbstractGeometryV2* newPartGeom, Changes& changes ) const
{
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
if ( dynamic_cast( geom ) )
{
QgsGeometryCollectionV2* GeomCollection = static_cast( geom );
@@ -161,10 +163,11 @@ void QgsGeometryCheck::replaceFeatureGeometryPart( QgsFeature& feature, int part
GeomCollection->addGeometry( newPartGeom );
changes[feature.id()].append( Change( ChangeFeature, ChangeRemoved, QgsVertexId( partIdx ) ) );
changes[feature.id()].append( Change( ChangeFeature, ChangeAdded, QgsVertexId( GeomCollection->partCount() - 1 ) ) );
+ feature.setGeometry( featureGeom );
}
else
{
- feature.setGeometry( new QgsGeometry( newPartGeom ) );
+ feature.setGeometry( QgsGeometry( newPartGeom ) );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
}
mFeaturePool->updateFeature( feature );
@@ -172,7 +175,8 @@ void QgsGeometryCheck::replaceFeatureGeometryPart( QgsFeature& feature, int part
void QgsGeometryCheck::deleteFeatureGeometryPart( QgsFeature &feature, int partIdx, Changes &changes ) const
{
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
if ( dynamic_cast( geom ) )
{
static_cast( geom )->removeGeometry( partIdx );
@@ -183,6 +187,7 @@ void QgsGeometryCheck::deleteFeatureGeometryPart( QgsFeature &feature, int partI
}
else
{
+ feature.setGeometry( featureGeom );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangePart, ChangeRemoved, QgsVertexId( partIdx ) ) );
}
@@ -196,7 +201,8 @@ void QgsGeometryCheck::deleteFeatureGeometryPart( QgsFeature &feature, int partI
void QgsGeometryCheck::deleteFeatureGeometryRing( QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const
{
- QgsAbstractGeometryV2* partGeom = QgsGeometryCheckerUtils::getGeomPart( feature.geometry()->geometry(), partIdx );
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* partGeom = QgsGeometryCheckerUtils::getGeomPart( featureGeom.geometry(), partIdx );
if ( dynamic_cast( partGeom ) )
{
// If we delete the exterior ring of a polygon, it makes no sense to keep the interiors
@@ -207,6 +213,7 @@ void QgsGeometryCheck::deleteFeatureGeometryRing( QgsFeature &feature, int partI
else
{
static_cast( partGeom )->removeInteriorRing( ringIdx - 1 );
+ feature.setGeometry( featureGeom );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeRing, ChangeRemoved, QgsVertexId( partIdx, ringIdx ) ) );
}
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp
index ceb0398c7bc..601bb2945c6 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp
@@ -29,9 +29,10 @@ void QgsGeometryContainedCheck::collectErrors( QList& er
continue;
}
- QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( featureGeom.geometry(), QgsGeometryCheckPrecision::tolerance() );
- QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->geometry()->boundingBox() );
+ QgsFeatureIds ids = mFeaturePool->getIntersects( featureGeom.geometry()->boundingBox() );
Q_FOREACH ( QgsFeatureId otherid, ids )
{
if ( otherid == featureid )
@@ -45,9 +46,9 @@ void QgsGeometryContainedCheck::collectErrors( QList& er
}
QString errMsg;
- if ( geomEngine->within( *otherFeature.geometry()->geometry(), &errMsg ) )
+ if ( geomEngine->within( *otherFeature.constGeometry()->geometry(), &errMsg ) )
{
- errors.append( new QgsGeometryContainedCheckError( this, featureid, feature.geometry()->geometry()->centroid(), otherid ) );
+ errors.append( new QgsGeometryContainedCheckError( this, featureid, feature.constGeometry()->geometry()->centroid(), otherid ) );
}
else if ( !errMsg.isEmpty() )
{
@@ -72,9 +73,10 @@ void QgsGeometryContainedCheck::fixError( QgsGeometryCheckError* error, int meth
}
// Check if error still applies
- QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( featureGeom.geometry(), QgsGeometryCheckPrecision::tolerance() );
- if ( !geomEngine->within( *otherFeature.geometry()->geometry() ) )
+ if ( !geomEngine->within( *otherFeature.constGeometry()->geometry() ) )
{
delete geomEngine;
error->setObsolete();
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp
index 5f00a4c1590..a0974d8d293 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp
@@ -27,7 +27,8 @@ void QgsGeometryDegeneratePolygonCheck::collectErrors( QListgeometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
@@ -49,7 +50,8 @@ void QgsGeometryDegeneratePolygonCheck::fixError( QgsGeometryCheckError* error,
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeometry = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeometry.geometry();
QgsVertexId vidx = error->vidx();
// Check if ring still exists
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp
index 694bbfd1833..187a97e37e1 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp
@@ -30,10 +30,11 @@ void QgsGeometryDuplicateCheck::collectErrors( QList& er
{
continue;
}
- QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( featureGeom.geometry(), QgsGeometryCheckPrecision::tolerance() );
QList duplicates;
- QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->geometry()->boundingBox() );
+ QgsFeatureIds ids = mFeaturePool->getIntersects( featureGeom.geometry()->boundingBox() );
Q_FOREACH ( QgsFeatureId id, ids )
{
// > : only report overlaps once
@@ -47,7 +48,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList& er
continue;
}
QString errMsg;
- QgsAbstractGeometryV2* diffGeom = geomEngine->symDifference( *testFeature.geometry()->geometry(), &errMsg );
+ QgsAbstractGeometryV2* diffGeom = geomEngine->symDifference( *testFeature.constGeometry()->geometry(), &errMsg );
if ( diffGeom && diffGeom->area() < QgsGeometryCheckPrecision::tolerance() )
{
duplicates.append( id );
@@ -61,7 +62,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList& er
if ( !duplicates.isEmpty() )
{
qSort( duplicates );
- errors.append( new QgsGeometryDuplicateCheckError( this, featureid, feature.geometry()->geometry()->centroid(), duplicates ) );
+ errors.append( new QgsGeometryDuplicateCheckError( this, featureid, feature.constGeometry()->geometry()->centroid(), duplicates ) );
}
delete geomEngine;
}
@@ -82,7 +83,8 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError* error, int meth
}
else if ( method == RemoveDuplicates )
{
- QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( featureGeom.geometry(), QgsGeometryCheckPrecision::tolerance() );
QgsGeometryDuplicateCheckError* duplicateError = static_cast( error );
Q_FOREACH ( QgsFeatureId id, duplicateError->duplicates() )
@@ -92,7 +94,7 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError* error, int meth
{
continue;
}
- QgsAbstractGeometryV2* diffGeom = geomEngine->symDifference( *testFeature.geometry()->geometry() );
+ QgsAbstractGeometryV2* diffGeom = geomEngine->symDifference( *testFeature.constGeometry()->geometry() );
if ( diffGeom && diffGeom->area() < QgsGeometryCheckPrecision::tolerance() )
{
mFeaturePool->deleteFeature( testFeature );
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp
index 92826edfa6f..94600b19e27 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp
@@ -29,7 +29,8 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( QListgeometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
@@ -59,7 +60,8 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError* error, int
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsVertexId vidx = error->vidx();
// Check if point still exists
@@ -96,6 +98,7 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError* error, int
}
else
{
+ feature.setGeometry( featureGeom );
mFeaturePool->updateFeature( feature );
error->setFixed( method );
changes[error->featureId()].append( Change( ChangeNode, ChangeRemoved, error->vidx() ) );
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
index 2f3e804b116..4085c52c279 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
@@ -32,7 +32,7 @@ void QgsGeometryGapCheck::collectErrors( QList& errors,
QgsFeature feature;
if ( mFeaturePool->get( id, feature ) )
{
- geomList.append( feature.geometry()->geometry()->clone() );
+ geomList.append( feature.constGeometry()->geometry()->clone() );
}
}
@@ -112,7 +112,8 @@ void QgsGeometryGapCheck::collectErrors( QList& errors,
{
continue;
}
- QgsAbstractGeometryV2* geom2 = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom2 = featureGeom.geometry();
if ( QgsGeometryCheckerUtils::sharedEdgeLength( geom, geom2, QgsGeometryCheckPrecision::reducedTolerance() ) > 0 )
{
neighboringIds.insert( feature.id() );
@@ -174,7 +175,8 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError* err, Chan
{
continue;
}
- QgsAbstractGeometryV2* testGeom = testFeature.geometry()->geometry();
+ QgsGeometry featureGeom = *testFeature.constGeometry();
+ QgsAbstractGeometryV2* testGeom = featureGeom.geometry();
for ( int iPart = 0, nParts = testGeom->partCount(); iPart < nParts; ++iPart )
{
double len = QgsGeometryCheckerUtils::sharedEdgeLength( errGeometry, QgsGeometryCheckerUtils::getGeomPart( testGeom, iPart ), QgsGeometryCheckPrecision::reducedTolerance() );
@@ -193,7 +195,8 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError* err, Chan
}
// Merge geometries
- QgsAbstractGeometryV2* mergeGeom = mergeFeature.geometry()->geometry();
+ QgsGeometry mergeFeatureGeom = *mergeFeature.constGeometry();
+ QgsAbstractGeometryV2* mergeGeom = mergeFeatureGeom.geometry();
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( errGeometry, QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* combinedGeom = geomEngine->combine( *QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), &errMsg );
delete geomEngine;
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
index 901bbc7c771..0fb37b8f9cf 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
@@ -28,7 +28,8 @@ void QgsGeometryHoleCheck::collectErrors( QList& errors,
continue;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
// Rings after the first one are interiors
@@ -48,7 +49,8 @@ void QgsGeometryHoleCheck::fixError( QgsGeometryCheckError* error, int method, i
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsVertexId vidx = error->vidx();
// Check if ring still exists
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp
index b333da141e4..064bd4dbfae 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp
@@ -27,7 +27,8 @@ void QgsGeometryMultipartCheck::collectErrors( QList& er
{
continue;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsWKBTypes::Type type = geom->wkbType();
if ( geom->partCount() == 1 && QgsWKBTypes::isMultiType( type ) )
@@ -45,7 +46,8 @@ void QgsGeometryMultipartCheck::fixError( QgsGeometryCheckError* error, int meth
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
// Check if error still applies
if ( geom->partCount() > 1 || !QgsWKBTypes::isMultiType( geom->wkbType() ) )
@@ -61,7 +63,7 @@ void QgsGeometryMultipartCheck::fixError( QgsGeometryCheckError* error, int meth
}
else if ( method == ConvertToSingle )
{
- feature.setGeometry( new QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, 0 )->clone() ) );
+ feature.setGeometry( QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, 0 )->clone() ) );
mFeaturePool->updateFeature( feature );
error->setFixed( method );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp
index f6471749c1d..51de5901c20 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp
@@ -28,10 +28,11 @@ void QgsGeometryOverlapCheck::collectErrors( QList& erro
{
continue;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( geom, QgsGeometryCheckPrecision::tolerance() );
- QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->boundingBox() );
+ QgsFeatureIds ids = mFeaturePool->getIntersects( feature.constGeometry()->boundingBox() );
Q_FOREACH ( QgsFeatureId otherid, ids )
{
// >= : only report overlaps once
@@ -47,9 +48,9 @@ void QgsGeometryOverlapCheck::collectErrors( QList& erro
}
QString errMsg;
- if ( geomEngine->overlaps( *otherFeature.geometry()->geometry(), &errMsg ) )
+ if ( geomEngine->overlaps( *otherFeature.constGeometry()->geometry(), &errMsg ) )
{
- QgsAbstractGeometryV2* interGeom = geomEngine->intersection( *otherFeature.geometry()->geometry() );
+ QgsAbstractGeometryV2* interGeom = geomEngine->intersection( *otherFeature.constGeometry()->geometry() );
if ( interGeom && !interGeom->isEmpty() )
{
QgsGeometryCheckerUtils::filter1DTypes( interGeom );
@@ -86,17 +87,18 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError* error, int method
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( geom, QgsGeometryCheckPrecision::tolerance() );
// Check if error still applies
- if ( !geomEngine->overlaps( *otherFeature.geometry()->geometry() ) )
+ if ( !geomEngine->overlaps( *otherFeature.constGeometry()->geometry() ) )
{
delete geomEngine;
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* interGeom = geomEngine->intersection( *otherFeature.geometry()->geometry(), &errMsg );
+ QgsAbstractGeometryV2* interGeom = geomEngine->intersection( *otherFeature.constGeometry()->geometry(), &errMsg );
delete geomEngine;
if ( !interGeom )
{
@@ -142,7 +144,8 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError* error, int method
{
QgsGeometryCheckerUtils::filter1DTypes( diff1 );
}
- QgsGeometryEngine* otherGeomEngine = QgsGeometryCheckerUtils::createGeomEngine( otherFeature.geometry()->geometry(), QgsGeometryCheckPrecision::reducedTolerance() );
+ QgsGeometry otherFeatureGeom = *otherFeature.constGeometry();
+ QgsGeometryEngine* otherGeomEngine = QgsGeometryCheckerUtils::createGeomEngine( otherFeatureGeom.geometry(), QgsGeometryCheckPrecision::reducedTolerance() );
QgsAbstractGeometryV2* diff2 = otherGeomEngine->difference( *interPart, &errMsg );
delete otherGeomEngine;
if ( !diff2 || diff2->isEmpty() )
@@ -164,7 +167,7 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError* error, int method
{
if ( shared1 < shared2 )
{
- feature.setGeometry( new QgsGeometry( diff1 ) );
+ feature.setGeometry( QgsGeometry( diff1 ) );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
mFeaturePool->updateFeature( feature );
@@ -173,7 +176,7 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError* error, int method
}
else
{
- otherFeature.setGeometry( new QgsGeometry( diff2 ) );
+ otherFeature.setGeometry( QgsGeometry( diff2 ) );
changes[otherFeature.id()].append( Change( ChangeFeature, ChangeChanged ) );
mFeaturePool->updateFeature( otherFeature );
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp
index a3201392673..07486ffe844 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp
@@ -30,7 +30,8 @@ void QgsGeometrySegmentLengthCheck::collectErrors( QList
{
continue;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
@@ -64,7 +65,9 @@ void QgsGeometrySegmentLengthCheck::fixError( QgsGeometryCheckError* error, int
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsVertexId vidx = error->vidx();
// Check if point still exists
diff --git a/src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp
index 8e5a0c21c7b..6ed59f040e1 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp
@@ -73,7 +73,8 @@ void QgsGeometrySelfIntersectionCheck::collectErrors( QListgeometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
@@ -96,7 +97,8 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsVertexId vidx = error->vidx();
// Check if ring still exists
@@ -194,6 +196,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
changes[feature.id()].append( Change( ChangeRing, ChangeRemoved, vidx ) );
changes[feature.id()].append( Change( ChangeRing, ChangeAdded, QgsVertexId( vidx.part, poly->ringCount() - 2 ) ) );
changes[feature.id()].append( Change( ChangeRing, ChangeAdded, QgsVertexId( vidx.part, poly->ringCount() - 1 ) ) );
+ feature.setGeometry( featureGeom );
mFeaturePool->updateFeature( feature );
}
else
@@ -232,6 +235,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
static_cast( geom )->addGeometry( poly2 );
changes[feature.id()].append( Change( ChangeRing, ChangeChanged, QgsVertexId( vidx.part, vidx.ring ) ) );
changes[feature.id()].append( Change( ChangePart, ChangeAdded, QgsVertexId( geom->partCount() - 1 ) ) );
+ feature.setGeometry( featureGeom );
mFeaturePool->updateFeature( feature );
}
// Otherwise, create multipolygon
@@ -240,7 +244,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
QgsMultiPolygonV2* multiPoly = new QgsMultiPolygonV2();
multiPoly->addGeometry( poly->clone() );
multiPoly->addGeometry( poly2 );
- feature.setGeometry( new QgsGeometry( multiPoly ) );
+ feature.setGeometry( QgsGeometry( multiPoly ) );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
}
@@ -249,7 +253,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
{
QgsFeature newFeature;
newFeature.setAttributes( feature.attributes() );
- newFeature.setGeometry( new QgsGeometry( poly2 ) );
+ newFeature.setGeometry( QgsGeometry( poly2 ) );
mFeaturePool->updateFeature( feature );
mFeaturePool->addFeature( newFeature );
changes[feature.id()].append( Change( ChangeRing, ChangeChanged, QgsVertexId( vidx.part, vidx.ring ) ) );
@@ -277,7 +281,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
QgsMultiCurveV2* geomCollection = new QgsMultiLineStringV2();
geomCollection->addGeometry( ringGeom1 );
geomCollection->addGeometry( ringGeom2 );
- feature.setGeometry( new QgsGeometry( geomCollection ) );
+ feature.setGeometry( QgsGeometry( geomCollection ) );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
}
@@ -289,19 +293,20 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError* error, i
QgsGeometryCollectionV2* geomCollection = static_cast( geom );
geomCollection->removeGeometry( vidx.part );
geomCollection->addGeometry( ringGeom1 );
+ feature.setGeometry( featureGeom );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangePart, ChangeRemoved, QgsVertexId( vidx.part ) ) );
changes[feature.id()].append( Change( ChangePart, ChangeAdded, QgsVertexId( geomCollection->partCount() - 1 ) ) );
}
else
{
- feature.setGeometry( new QgsGeometry( ringGeom1 ) );
+ feature.setGeometry( QgsGeometry( ringGeom1 ) );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged, QgsVertexId( vidx.part ) ) );
}
QgsFeature newFeature;
newFeature.setAttributes( feature.attributes() );
- newFeature.setGeometry( new QgsGeometry( ringGeom2 ) );
+ newFeature.setGeometry( QgsGeometry( ringGeom2 ) );
mFeaturePool->addFeature( newFeature );
changes[newFeature.id()].append( Change( ChangeFeature, ChangeAdded ) );
}
diff --git a/src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp
index b83a00ff3a9..ec7a8f4a76e 100644
--- a/src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp
+++ b/src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp
@@ -34,7 +34,8 @@ void QgsGeometryTypeCheck::collectErrors( QList& errors,
{
continue;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
QgsWKBTypes::Type type = QgsWKBTypes::flatType( geom->wkbType() );
if (( mAllowedTypes & ( 1 << type ) ) == 0 )
@@ -52,7 +53,8 @@ void QgsGeometryTypeCheck::fixError( QgsGeometryCheckError* error, int method, i
error->setObsolete();
return;
}
- QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* geom = featureGeom.geometry();
// Check if error still applies
QgsWKBTypes::Type type = QgsWKBTypes::flatType( geom->wkbType() );
@@ -77,12 +79,12 @@ void QgsGeometryTypeCheck::fixError( QgsGeometryCheckError* error, int method, i
{
QgsFeature newFeature;
newFeature.setAttributes( feature.attributes() );
- newFeature.setGeometry( new QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, iPart )->clone() ) );
+ newFeature.setGeometry( QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, iPart )->clone() ) );
mFeaturePool->addFeature( newFeature );
changes[newFeature.id()].append( Change( ChangeFeature, ChangeAdded ) );
}
// Recycle feature for part 0
- feature.setGeometry( new QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, 0 )->clone() ) );
+ feature.setGeometry( QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, 0 )->clone() ) );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
}
@@ -128,7 +130,7 @@ void QgsGeometryTypeCheck::fixError( QgsGeometryCheckError* error, int method, i
{
geomCollection->addGeometry( geom->clone() );
- feature.setGeometry( new QgsGeometry( geomCollection ) );
+ feature.setGeometry( QgsGeometry( geomCollection ) );
mFeaturePool->updateFeature( feature );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
}
diff --git a/src/plugins/geometry_checker/qgsgeometrychecker.cpp b/src/plugins/geometry_checker/qgsgeometrychecker.cpp
index 3c3a4106904..c8acc354d70 100644
--- a/src/plugins/geometry_checker/qgsgeometrychecker.cpp
+++ b/src/plugins/geometry_checker/qgsgeometrychecker.cpp
@@ -117,7 +117,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError* error, int method )
if ( mFeaturePool->get( id, f ) )
{
recheckFeatures.insert( id );
- recheckArea.unionRect( f.geometry()->boundingBox() );
+ recheckArea.unionRect( f.constGeometry()->boundingBox() );
}
}
}
diff --git a/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp b/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp
index 47d32f9f369..970ac0c195b 100644
--- a/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp
+++ b/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp
@@ -271,7 +271,7 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString& file )
QgsFeature f( layer->fields() );
f.setAttribute( fieldFeatureId, error->featureId() );
f.setAttribute( fieldErrDesc, error->description() );
- f.setGeometry( new QgsGeometry( error->location().clone() ) );
+ f.setGeometry( QgsGeometry( error->location().clone() ) );
layer->dataProvider()->addFeatures( QgsFeatureList() << f );
}
@@ -331,7 +331,7 @@ void QgsGeometryCheckerResultTab::highlightErrors( bool current )
{
QgsRubberBand* featureRubberBand = new QgsRubberBand( mIface->mapCanvas() );
QgsGeometry geom( geometry->clone() );
- featureRubberBand->addGeometry( &geom, mFeaturePool->getLayer() );
+ featureRubberBand->addGeometry( geom, mFeaturePool->getLayer() );
featureRubberBand->setWidth( 5 );
featureRubberBand->setColor( Qt::yellow );
mCurrentRubberBands.append( featureRubberBand );
diff --git a/src/plugins/geometry_checker/utils/qgsfeaturepool.cpp b/src/plugins/geometry_checker/utils/qgsfeaturepool.cpp
index 650b0c0f46a..b781393fc1f 100644
--- a/src/plugins/geometry_checker/utils/qgsfeaturepool.cpp
+++ b/src/plugins/geometry_checker/utils/qgsfeaturepool.cpp
@@ -98,7 +98,7 @@ void QgsFeaturePool::addFeature( QgsFeature& feature )
void QgsFeaturePool::updateFeature( QgsFeature& feature )
{
QgsGeometryMap geometryMap;
- geometryMap.insert( feature.id(), QgsGeometry( feature.geometry()->geometry()->clone() ) );
+ geometryMap.insert( feature.id(), QgsGeometry( feature.constGeometry()->geometry()->clone() ) );
QgsChangedAttributesMap changedAttributesMap;
QgsAttributeMap attribMap;
for ( int i = 0, n = feature.attributes().size(); i < n; ++i )
diff --git a/src/plugins/geometry_snapper/qgsgeometrysnapper.cpp b/src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
index b173bb13ecc..a65b82dba28 100644
--- a/src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
+++ b/src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
@@ -70,24 +70,24 @@ void QgsGeometrySnapper::processFeature( QgsFeatureId id )
mErrorMutex.unlock();
return;
}
- QgsPointV2 center = QgsPointV2( feature.geometry()->geometry()->boundingBox().center() );
+ QgsPointV2 center = QgsPointV2( feature.constGeometry()->geometry()->boundingBox().center() );
// Compute snap tolerance
- double layerToMapUnits = mMapSettings->layerToMapUnits( mAdjustLayer, feature.geometry()->boundingBox() );
+ double layerToMapUnits = mMapSettings->layerToMapUnits( mAdjustLayer, feature.constGeometry()->boundingBox() );
double snapTolerance = mSnapToleranceMapUnits / layerToMapUnits;
// Get potential reference features and construct snap index
QList refGeometries;
mIndexMutex.lock();
- QList refFeatureIds = mIndex.intersects( feature.geometry()->boundingBox() );
+ QList refFeatureIds = mIndex.intersects( feature.constGeometry()->boundingBox() );
mIndexMutex.unlock();
Q_FOREACH ( QgsFeatureId refId, refFeatureIds )
{
QgsFeature refFeature;
if ( getFeature( mReferenceLayer, mReferenceLayerMutex, refId, refFeature ) )
{
- refGeometries.append( refFeature.geometry()->geometry()->clone() );
+ refGeometries.append( refFeature.constGeometry()->geometry()->clone() );
}
else
{
@@ -103,7 +103,8 @@ void QgsGeometrySnapper::processFeature( QgsFeatureId id )
}
// Snap geometries
- QgsAbstractGeometryV2* subjGeom = feature.geometry()->geometry();
+ QgsGeometry featureGeom = *feature.constGeometry();
+ QgsAbstractGeometryV2* subjGeom = featureGeom.geometry();
QList < QList< QList > > subjPointFlags;
// Pass 1: snap vertices of subject geometry to reference vertices
@@ -239,9 +240,9 @@ void QgsGeometrySnapper::processFeature( QgsFeatureId id )
}
}
- feature.setGeometry( new QgsGeometry( feature.geometry()->geometry()->clone() ) ); // force refresh
+ feature.setGeometry( QgsGeometry( featureGeom.geometry()->clone() ) ); // force refresh
QgsGeometryMap geometryMap;
- geometryMap.insert( id, *feature.geometry() );
+ geometryMap.insert( id, *feature.constGeometry() );
qDeleteAll( refGeometries );
mAdjustLayerMutex.lock();
mAdjustLayer->dataProvider()->changeGeometryValues( geometryMap );
diff --git a/src/plugins/globe/featuresource/qgsglobefeaturesource.cpp b/src/plugins/globe/featuresource/qgsglobefeaturesource.cpp
index e2ca03e5151..49f955ca631 100644
--- a/src/plugins/globe/featuresource/qgsglobefeaturesource.cpp
+++ b/src/plugins/globe/featuresource/qgsglobefeaturesource.cpp
@@ -40,7 +40,7 @@ void QgsGlobeFeatureSource::initialize( const osgDB::Options* dbOptions )
mLayer = mOptions.layer();
connect( mLayer, SIGNAL( attributeValueChanged( QgsFeatureId, int, QVariant ) ), this, SLOT( attributeValueChanged( QgsFeatureId, int, QVariant ) ) );
- connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry& ) ) );
+ connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry& ) ) );
// create the profile
osgEarth::SpatialReference* ref = osgEarth::SpatialReference::create( mLayer->crs().toWkt().toStdString() );
@@ -126,7 +126,7 @@ void QgsGlobeFeatureSource::attributeValueChanged( const QgsFeatureId& featureId
}
}
-void QgsGlobeFeatureSource::geometryChanged( const QgsFeatureId& featureId, QgsGeometry& geometry )
+void QgsGlobeFeatureSource::geometryChanged( const QgsFeatureId& featureId, const QgsGeometry& geometry )
{
FeatureMap_t::iterator it = mFeatures.find( featureId );
if ( it != mFeatures.end() )
diff --git a/src/plugins/globe/featuresource/qgsglobefeaturesource.h b/src/plugins/globe/featuresource/qgsglobefeaturesource.h
index deddb86e97b..124789f652d 100644
--- a/src/plugins/globe/featuresource/qgsglobefeaturesource.h
+++ b/src/plugins/globe/featuresource/qgsglobefeaturesource.h
@@ -56,7 +56,7 @@ class QgsGlobeFeatureSource : public QObject, public osgEarth::Features::Feature
private slots:
void attributeValueChanged( const QgsFeatureId&featureId, int idx, const QVariant &value );
- void geometryChanged( const QgsFeatureId&featureId, QgsGeometry&geometry );
+ void geometryChanged( const QgsFeatureId&featureId, const QgsGeometry& geometry );
};
#endif // QGSGLOBEFEATURESOURCE_H
diff --git a/src/plugins/roadgraph/shortestpathwidget.cpp b/src/plugins/roadgraph/shortestpathwidget.cpp
index 397b46c5cde..bb42d03c78b 100644
--- a/src/plugins/roadgraph/shortestpathwidget.cpp
+++ b/src/plugins/roadgraph/shortestpathwidget.cpp
@@ -435,7 +435,9 @@ void RgShortestPathWidget::exportPath()
QgsFeature f;
f.initAttributes( vl->fields().count() );
- f.setGeometry( QgsGeometry::fromPolyline( p ) );
+ QgsGeometry* g = QgsGeometry::fromPolyline( p );
+ f.setGeometry( *g );
+ delete g;
f.setAttribute( 0, cost / distanceUnit.multipler() );
f.setAttribute( 1, time / timeUnit.multipler() );
QgsFeatureList features;
diff --git a/src/plugins/spatialquery/qgsrubberselectid.cpp b/src/plugins/spatialquery/qgsrubberselectid.cpp
index a4e0ba112a1..99377ab2c29 100644
--- a/src/plugins/spatialquery/qgsrubberselectid.cpp
+++ b/src/plugins/spatialquery/qgsrubberselectid.cpp
@@ -72,7 +72,7 @@ void QgsRubberSelectId::addFeature( QgsVectorLayer* lyr, QgsFeatureId fid )
{
return;
}
- mRubberBand->setToGeometry( feat.constGeometry(), lyr );
+ mRubberBand->setToGeometry( *feat.constGeometry(), lyr );
} // void QgsRubberSelectId::addFeature( QgsVectorLayer* mLayer, int Id )
void QgsRubberSelectId::show()
diff --git a/src/plugins/spatialquery/qgsspatialquery.cpp b/src/plugins/spatialquery/qgsspatialquery.cpp
index c2d839f8120..705405835bb 100644
--- a/src/plugins/spatialquery/qgsspatialquery.cpp
+++ b/src/plugins/spatialquery/qgsspatialquery.cpp
@@ -245,13 +245,12 @@ void QgsSpatialQuery::execQuery( QgsFeatureIds &qsetIndexResult, QgsFeatureIds &
coordinateTransform->setCoordinateTransform( mLayerTarget, mLayerReference );
// Set function for populate result
- void ( QgsSpatialQuery::* funcPopulateIndexResult )( QgsFeatureIds&, QgsFeatureId, QgsGeometry *, bool ( QgsGeometryEngine::* )( const QgsAbstractGeometryV2&, QString* ) const );
+ void ( QgsSpatialQuery::* funcPopulateIndexResult )( QgsFeatureIds&, QgsFeatureId, const QgsGeometry&, bool ( QgsGeometryEngine::* )( const QgsAbstractGeometryV2&, QString* ) const );
funcPopulateIndexResult = ( relation == Disjoint )
? &QgsSpatialQuery::populateIndexResultDisjoint
: &QgsSpatialQuery::populateIndexResult;
QgsFeature featureTarget;
- QgsGeometry * geomTarget;
int step = 1;
while ( mReaderFeaturesTarget->nextFeature( featureTarget ) )
{
@@ -263,8 +262,8 @@ void QgsSpatialQuery::execQuery( QgsFeatureIds &qsetIndexResult, QgsFeatureIds &
continue;
}
- geomTarget = featureTarget.geometry();
- coordinateTransform->transform( geomTarget );
+ QgsGeometry geomTarget = *featureTarget.constGeometry();
+ coordinateTransform->transform( &geomTarget );
( this->*funcPopulateIndexResult )( qsetIndexResult, featureTarget.id(), geomTarget, operation );
}
@@ -273,17 +272,17 @@ void QgsSpatialQuery::execQuery( QgsFeatureIds &qsetIndexResult, QgsFeatureIds &
} // QSet QgsSpatialQuery::execQuery( QSet & qsetIndexResult, int relation)
void QgsSpatialQuery::populateIndexResult(
- QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, QgsGeometry * geomTarget,
+ QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, const QgsGeometry& geomTarget,
bool ( QgsGeometryEngine::* op )( const QgsAbstractGeometryV2&, QString* ) const )
{
- QgsFeatureIds listIdReference = mIndexReference.intersects( geomTarget->boundingBox() ).toSet();
+ QgsFeatureIds listIdReference = mIndexReference.intersects( geomTarget.boundingBox() ).toSet();
if ( listIdReference.isEmpty() )
{
return;
}
//prepare geometry
- QgsGeometryEngine* geomEngine = geomTarget->createGeometryEngine( geomTarget->geometry() );
+ QgsGeometryEngine* geomEngine = geomTarget.createGeometryEngine( geomTarget.geometry() );
geomEngine->prepareGeometry();
QgsFeature featureReference;
@@ -305,10 +304,10 @@ void QgsSpatialQuery::populateIndexResult(
} // void QgsSpatialQuery::populateIndexResult(...
void QgsSpatialQuery::populateIndexResultDisjoint(
- QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, QgsGeometry * geomTarget,
+ QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, const QgsGeometry& geomTarget,
bool ( QgsGeometryEngine::* op )( const QgsAbstractGeometryV2&, QString* ) const )
{
- QgsFeatureIds listIdReference = mIndexReference.intersects( geomTarget->boundingBox() ).toSet();
+ QgsFeatureIds listIdReference = mIndexReference.intersects( geomTarget.boundingBox() ).toSet();
if ( listIdReference.isEmpty() )
{
qsetIndexResult.insert( idTarget );
@@ -316,7 +315,7 @@ void QgsSpatialQuery::populateIndexResultDisjoint(
}
//prepare geometry
- QgsGeometryEngine* geomEngine = geomTarget->createGeometryEngine( geomTarget->geometry() );
+ QgsGeometryEngine* geomEngine = geomTarget.createGeometryEngine( geomTarget.geometry() );
geomEngine->prepareGeometry();
QgsFeature featureReference;
diff --git a/src/plugins/spatialquery/qgsspatialquery.h b/src/plugins/spatialquery/qgsspatialquery.h
index b9ac2c2df37..279fa0c6353 100644
--- a/src/plugins/spatialquery/qgsspatialquery.h
+++ b/src/plugins/spatialquery/qgsspatialquery.h
@@ -136,9 +136,8 @@ class QgsSpatialQuery
* \param geomTarget Geometry the feature Target
* \param operation Pointer to function of GEOS operation
*/
- void populateIndexResult(
- QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, QgsGeometry *geomTarget,
- bool ( QgsGeometryEngine::* operation )( const QgsAbstractGeometryV2&, QString* ) const );
+ void populateIndexResult( QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, const QgsGeometry& geomTarget,
+ bool ( QgsGeometryEngine::* operation )( const QgsAbstractGeometryV2&, QString* ) const );
/**
* \brief Populate index Result Disjoint
* \param qsetIndexResult Reference to QSet contains the result query
@@ -146,7 +145,7 @@ class QgsSpatialQuery
* \param geomTarget Geometry the feature Target
* \param operation Pointer to function of GEOS operation
*/
- void populateIndexResultDisjoint( QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, QgsGeometry *geomTarget,
+ void populateIndexResultDisjoint( QgsFeatureIds &qsetIndexResult, QgsFeatureId idTarget, const QgsGeometry& geomTarget,
bool ( QgsGeometryEngine::*operation )( const QgsAbstractGeometryV2&, QString* ) const );
MngProgressBar *mPb;
diff --git a/src/plugins/topology/checkDock.cpp b/src/plugins/topology/checkDock.cpp
index 4e072344b1e..47f118c615b 100644
--- a/src/plugins/topology/checkDock.cpp
+++ b/src/plugins/topology/checkDock.cpp
@@ -243,7 +243,7 @@ void checkDock::errorListClicked( const QModelIndex& index )
mVMFeature1->setCenter( g->asPoint() );
}
else
- mRBFeature1->setToGeometry( g, fl.layer );
+ mRBFeature1->setToGeometry( *g, fl.layer );
fl = mErrorList[row]->featurePairs()[1];
if ( !fl.layer )
@@ -272,7 +272,7 @@ void checkDock::errorListClicked( const QModelIndex& index )
mVMFeature2->setCenter( g->asPoint() );
}
else
- mRBFeature2->setToGeometry( g, fl.layer );
+ mRBFeature2->setToGeometry( *g, fl.layer );
if ( !mErrorList[row]->conflict() )
{
@@ -290,7 +290,7 @@ void checkDock::errorListClicked( const QModelIndex& index )
mVMConflict->setCenter( mErrorList.at( row )->conflict()->asPoint() );
}
else
- mRBConflict->setToGeometry( mErrorList.at( row )->conflict(), fl.layer );
+ mRBConflict->setToGeometry( *mErrorList.at( row )->conflict(), fl.layer );
}
void checkDock::fix()
@@ -369,7 +369,7 @@ void checkDock::runTests( ValidateType type )
}
rb->setColor( "red" );
rb->setWidth( 4 );
- rb->setToGeometry( te->conflict(), layer1 );
+ rb->setToGeometry( *te->conflict(), layer1 );
rb->show();
mRbErrorMarkers << rb;
}
diff --git a/src/plugins/topology/topolError.cpp b/src/plugins/topology/topolError.cpp
index b130866e508..1c64564233c 100644
--- a/src/plugins/topology/topolError.cpp
+++ b/src/plugins/topology/topolError.cpp
@@ -39,8 +39,11 @@ bool TopolError::fixMove( FeatureLayer fl1, FeatureLayer fl2 )
// 0 means success
- if ( !f1.geometry()->makeDifference( f2.constGeometry() ) )
- return fl1.layer->changeGeometry( f1.id(), f1.geometry() );
+ QgsGeometry g = *f1.constGeometry();
+ if ( g.makeDifference( f2.constGeometry() ) == 0 )
+ {
+ return fl1.layer->changeGeometry( f1.id(), g );
+ }
return false;
}
@@ -71,7 +74,7 @@ bool TopolError::fixUnion( FeatureLayer fl1, FeatureLayer fl2 )
return false;
if ( fl2.layer->deleteFeature( f2.id() ) )
- return fl1.layer->changeGeometry( f1.id(), g.data() );
+ return fl1.layer->changeGeometry( f1.id(), *g.data() );
return false;
}
@@ -95,7 +98,7 @@ bool TopolError::fixSnap()
line.last() = conflictLine.last();
QgsGeometry* newG = QgsGeometry::fromPolyline( line );
- bool ret = fl.layer->changeGeometry( f1.id(), newG );
+ bool ret = fl.layer->changeGeometry( f1.id(), *newG );
delete newG;
return ret;
diff --git a/src/plugins/topology/topolTest.cpp b/src/plugins/topology/topolTest.cpp
index 60aadcfedf3..ef845723305 100644
--- a/src/plugins/topology/topolTest.cpp
+++ b/src/plugins/topology/topolTest.cpp
@@ -258,23 +258,23 @@ ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
+ QgsGeometry g1 = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
- if ( !g1 )
+ if ( g1.isEmpty() )
{
QgsMessageLog::logMessage( tr( "First geometry invalid in dangling line test." ), tr( "Topology plugin" ) );
continue;
}
- if ( !g1->asGeos() )
+ if ( !g1.asGeos() )
{
QgsMessageLog::logMessage( tr( "Failed to import first geometry into GEOS in dangling line test." ), tr( "Topology plugin" ) );
continue;
}
- if ( g1->isMultipart() )
+ if ( g1.isMultipart() )
{
- QgsMultiPolyline lines = g1->asMultiPolyline();
+ QgsMultiPolyline lines = g1.asMultiPolyline();
for ( int m = 0; m < lines.count(); m++ )
{
QgsPolyline line = lines[m];
@@ -288,7 +288,7 @@ ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer
}
else
{
- QgsPolyline polyline = g1->asPolyline();
+ QgsPolyline polyline = g1.asPolyline();
startPoint = polyline[0];
endPoint = polyline[polyline.size()-1];
endVerticesMap.insert( std::pair( startPoint, it->feature.id() ) );
@@ -587,7 +587,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
}
QList::iterator it;
- QgsGeometry* g1;
+ QgsGeometry g1;
QList geomList;
@@ -606,27 +606,27 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
break;
}
- g1 = it->feature.geometry();
+ g1 = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
- if ( !g1 )
+ if ( g1.isEmpty() )
{
continue;
}
- if ( !g1->asGeos() )
+ if ( !g1.asGeos() )
{
continue;
}
- if ( !g1->isGeosValid() )
+ if ( !g1.isGeosValid() )
{
qDebug() << "invalid geometry found..skipping.." << it->feature.id();
continue;
}
- if ( g1->isMultipart() )
+ if ( g1.isMultipart() )
{
- QgsMultiPolygon polys = g1->asMultiPolygon();
+ QgsMultiPolygon polys = g1.asMultiPolygon();
for ( int m = 0; m < polys.count(); m++ )
{
QgsPolygon polygon = polys[m];
@@ -640,7 +640,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
}
else
{
- geomList.push_back( GEOSGeom_clone_r( geosctxt, g1->asGeos() ) );
+ geomList.push_back( GEOSGeom_clone_r( geosctxt, g1.asGeos() ) );
}
}
@@ -754,23 +754,23 @@ ErrorList topolTest::checkPseudos( double tolerance, QgsVectorLayer *layer1, Qgs
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
+ QgsGeometry g1 = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
- if ( !g1 )
+ if ( g1.isEmpty() )
{
QgsMessageLog::logMessage( tr( "Skipping invalid first geometry in pseudo line test." ), tr( "Topology plugin" ) );
continue;
}
- if ( !g1->asGeos() )
+ if ( !g1.asGeos() )
{
QgsMessageLog::logMessage( tr( "Failed to import first geometry into GEOS in pseudo line test." ), tr( "Topology plugin" ) );
continue;
}
- if ( g1->isMultipart() )
+ if ( g1.isMultipart() )
{
- QgsMultiPolyline lines = g1->asMultiPolyline();
+ QgsMultiPolyline lines = g1.asMultiPolyline();
for ( int m = 0; m < lines.count(); m++ )
{
QgsPolyline line = lines[m];
@@ -784,7 +784,7 @@ ErrorList topolTest::checkPseudos( double tolerance, QgsVectorLayer *layer1, Qgs
}
else
{
- QgsPolyline polyline = g1->asPolyline();
+ QgsPolyline polyline = g1.asPolyline();
startPoint = polyline[0];
endPoint = polyline[polyline.size()-1];
endVerticesMap.insert( std::pair( startPoint, it->feature.id() ) );
@@ -857,23 +857,23 @@ ErrorList topolTest::checkValid( double tolerance, QgsVectorLayer* layer1, QgsVe
if ( testCancelled() )
break;
- QgsGeometry* g = it->feature.geometry();
- if ( !g )
+ QgsGeometry g = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
+ if ( g.isEmpty() )
{
QgsMessageLog::logMessage( tr( "Invalid geometry in validity test." ), tr( "Topology plugin" ) );
continue;
}
- if ( !g->asGeos() )
+ if ( !g.asGeos() )
continue;
- if ( !GEOSisValid_r( QgsGeometry::getGEOSHandler(), g->asGeos() ) )
+ if ( !GEOSisValid_r( QgsGeometry::getGEOSHandler(), g.asGeos() ) )
{
- QgsRectangle r = g->boundingBox();
+ QgsRectangle r = g.boundingBox();
QList fls;
fls << *it << *it;
- QgsGeometry* conflict = new QgsGeometry( *g );
+ QgsGeometry* conflict = new QgsGeometry( g );
TopolErrorValid* err = new TopolErrorValid( r, conflict, fls );
errorList << err;
}
@@ -913,8 +913,8 @@ ErrorList topolTest::checkPointCoveredBySegment( double tolerance, QgsVectorLaye
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
- QgsRectangle bb = g1->boundingBox();
+ QgsGeometry g1 = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
+ QgsRectangle bb = g1.boundingBox();
QList crossingIds;
crossingIds = index->intersects( bb );
@@ -936,7 +936,7 @@ ErrorList topolTest::checkPointCoveredBySegment( double tolerance, QgsVectorLaye
}
// test if point touches other geometry
- if ( g1->touches( g2 ) )
+ if ( g1.touches( g2 ) )
{
touched = true;
break;
@@ -945,7 +945,7 @@ ErrorList topolTest::checkPointCoveredBySegment( double tolerance, QgsVectorLaye
if ( !touched )
{
- QgsGeometry* conflictGeom = new QgsGeometry( *g1 );
+ QgsGeometry* conflictGeom = new QgsGeometry( g1 );
if ( isExtent )
{
@@ -1004,15 +1004,15 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
break;
}
- QgsGeometry* g1 = it->feature.geometry();
+ QgsGeometry g1 = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
// switching by type here, because layer can contain both single and multi version geometries
- switch ( g1->wkbType() )
+ switch ( g1.wkbType() )
{
case Qgis::WKBLineString:
case Qgis::WKBLineString25D:
- ls = g1->asPolyline();
+ ls = g1.asPolyline();
for ( int i = 1; i < ls.size(); ++i )
@@ -1025,7 +1025,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
segm.clear();
segm << ls[i-1] << ls[i];
QgsGeometry* conflict = QgsGeometry::fromPolyline( segm );
- err = new TopolErrorShort( g1->boundingBox(), conflict, fls );
+ err = new TopolErrorShort( g1.boundingBox(), conflict, fls );
//err = new TopolErrorShort(g1->boundingBox(), QgsGeometry::fromPolyline(segm), fls);
errorList << err;
//break on getting the first error
@@ -1036,7 +1036,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
case Qgis::WKBPolygon:
case Qgis::WKBPolygon25D:
- pol = g1->asPolygon();
+ pol = g1.asPolygon();
for ( int i = 0; i < pol.size(); ++i )
{
@@ -1050,7 +1050,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
segm.clear();
segm << pol[i][j-1] << pol[i][j];
QgsGeometry* conflict = QgsGeometry::fromPolyline( segm );
- err = new TopolErrorShort( g1->boundingBox(), conflict, fls );
+ err = new TopolErrorShort( g1.boundingBox(), conflict, fls );
errorList << err;
//break on getting the first error
break;
@@ -1062,7 +1062,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
case Qgis::WKBMultiLineString:
case Qgis::WKBMultiLineString25D:
- mls = g1->asMultiPolyline();
+ mls = g1.asMultiPolyline();
for ( int k = 0; k < mls.size(); ++k )
{
@@ -1077,7 +1077,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
segm.clear();
segm << ls[i-1] << ls[i];
QgsGeometry* conflict = QgsGeometry::fromPolyline( segm );
- err = new TopolErrorShort( g1->boundingBox(), conflict, fls );
+ err = new TopolErrorShort( g1.boundingBox(), conflict, fls );
errorList << err;
//break on getting the first error
break;
@@ -1088,7 +1088,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
case Qgis::WKBMultiPolygon:
case Qgis::WKBMultiPolygon25D:
- mpol = g1->asMultiPolygon();
+ mpol = g1.asMultiPolygon();
for ( int k = 0; k < mpol.size(); ++k )
{
@@ -1105,7 +1105,7 @@ ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer
segm.clear();
segm << pol[i][j-1] << pol[i][j];
QgsGeometry* conflict = QgsGeometry::fromPolyline( segm );
- err = new TopolErrorShort( g1->boundingBox(), conflict, fls );
+ err = new TopolErrorShort( g1.boundingBox(), conflict, fls );
errorList << err;
//break on getting the first error
break;
@@ -1145,8 +1145,8 @@ ErrorList topolTest::checkOverlapWithLayer( double tolerance, QgsVectorLayer* la
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
- QgsRectangle bb = g1->boundingBox();
+ QgsGeometry g1 = *it->feature.constGeometry();
+ QgsRectangle bb = g1.boundingBox();
QList crossingIds;
crossingIds = index->intersects( bb );
@@ -1168,13 +1168,13 @@ ErrorList topolTest::checkOverlapWithLayer( double tolerance, QgsVectorLayer* la
continue;
}
- if ( g1->overlaps( g2 ) )
+ if ( g1.overlaps( g2 ) )
{
QgsRectangle r = bb;
QgsRectangle r2 = g2->boundingBox();
r.combineExtentWith( r2 );
- QScopedPointer conflictGeom( g1->intersection( g2 ) );
+ QScopedPointer conflictGeom( g1.intersection( g2 ) );
// could this for some reason return NULL?
if ( !conflictGeom )
{
@@ -1241,8 +1241,8 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
emit progress( i );
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
- QgsRectangle bb = g1->boundingBox();
+ QgsGeometry g1 = *it->feature.constGeometry();
+ QgsRectangle bb = g1.boundingBox();
QList crossingIds;
crossingIds = index->intersects( bb );
QList::Iterator cit = crossingIds.begin();
@@ -1260,7 +1260,7 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
QgsPolyline g2Line = g2->asPolyline();
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2Line.at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2Line.last() );
- touched = g1->intersects( startPoint ) || g1->intersects( endPoint );
+ touched = g1.intersects( startPoint ) || g1.intersects( endPoint );
delete startPoint;
delete endPoint;
@@ -1271,7 +1271,7 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
}
if ( !touched )
{
- QgsGeometry* conflictGeom = new QgsGeometry( *g1 );
+ QgsGeometry* conflictGeom = new QgsGeometry( g1 );
if ( isExtent )
{
if ( canvasExtentPoly->disjoint( conflictGeom ) )
@@ -1322,13 +1322,13 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
emit progress( i );
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
+ QgsGeometry g1 = *it->feature.constGeometry();
- QgsPolyline g1Polyline = g1->asPolyline();
+ QgsPolyline g1Polyline = g1.asPolyline();
QgsGeometry* startPoint = QgsGeometry::fromPoint( g1Polyline.at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g1Polyline.last() );
- QgsRectangle bb = g1->boundingBox();
+ QgsRectangle bb = g1.boundingBox();
QList crossingIds;
crossingIds = index->intersects( bb );
QList::Iterator cit = crossingIds.begin();
@@ -1371,7 +1371,7 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
if ( !touched )
{
- QScopedPointer conflictGeom( new QgsGeometry( *g1 ) );
+ QScopedPointer conflictGeom( new QgsGeometry( g1 ) );
if ( isExtent )
{
@@ -1424,8 +1424,8 @@ ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *laye
emit progress( i );
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
- QgsRectangle bb = g1->boundingBox();
+ QgsGeometry g1 = *it->feature.constGeometry();
+ QgsRectangle bb = g1.boundingBox();
QList crossingIds;
crossingIds = index->intersects( bb );
QList::Iterator cit = crossingIds.begin();
@@ -1440,7 +1440,7 @@ ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *laye
QgsMessageLog::logMessage( tr( "Second geometry missing or GEOS import failed." ), tr( "Topology plugin" ) );
continue;
}
- if ( g2->contains( g1 ) )
+ if ( g2->contains( &g1 ) )
{
touched = true;
break;
@@ -1448,7 +1448,7 @@ ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *laye
}
if ( !touched )
{
- QgsGeometry* conflictGeom = new QgsGeometry( *g1 );
+ QgsGeometry* conflictGeom = new QgsGeometry( g1 );
if ( isExtent )
{
@@ -1500,8 +1500,8 @@ ErrorList topolTest::checkPolygonContainsPoint( double tolerance, QgsVectorLayer
emit progress( i );
if ( testCancelled() )
break;
- QgsGeometry* g1 = it->feature.geometry();
- QgsRectangle bb = g1->boundingBox();
+ QgsGeometry g1 = *it->feature.constGeometry();
+ QgsRectangle bb = g1.boundingBox();
QList crossingIds;
crossingIds = index->intersects( bb );
QList::Iterator cit = crossingIds.begin();
@@ -1516,7 +1516,7 @@ ErrorList topolTest::checkPolygonContainsPoint( double tolerance, QgsVectorLayer
QgsMessageLog::logMessage( tr( "Second geometry missing or GEOS import failed." ), tr( "Topology plugin" ) );
continue;
}
- if ( g1->contains( g2 ) )
+ if ( g1.contains( g2 ) )
{
touched = true;
break;
@@ -1527,7 +1527,7 @@ ErrorList topolTest::checkPolygonContainsPoint( double tolerance, QgsVectorLayer
QList fls;
fls << *it << *it;
//bb.scale(10);
- QgsGeometry* conflict = new QgsGeometry( *g1 );
+ QgsGeometry* conflict = new QgsGeometry( g1 );
TopolErrorPolygonContainsPoint* err = new TopolErrorPolygonContainsPoint( bb, conflict, fls );
errorList << err;
}
@@ -1551,20 +1551,20 @@ ErrorList topolTest::checkMultipart( double tolerance, QgsVectorLayer *layer1, Q
emit progress( ++i );
if ( testCancelled() )
break;
- QgsGeometry* g = it->feature.geometry();
- if ( !g )
+ QgsGeometry g = it->feature.constGeometry() ? *it->feature.constGeometry() : QgsGeometry();
+ if ( g.isEmpty() )
{
QgsMessageLog::logMessage( tr( "Missing geometry in multipart check." ), tr( "Topology plugin" ) );
continue;
}
- if ( !g->asGeos() )
+ if ( !g.asGeos() )
continue;
- if ( g->isMultipart() )
+ if ( g.isMultipart() )
{
- QgsRectangle r = g->boundingBox();
+ QgsRectangle r = g.boundingBox();
QList fls;
fls << *it << *it;
- QgsGeometry* conflict = new QgsGeometry( *g );
+ QgsGeometry* conflict = new QgsGeometry( g );
TopolErroMultiPart* err = new TopolErroMultiPart( r, conflict, fls );
errorList << err;
}
diff --git a/src/providers/arcgisrest/qgsafsprovider.cpp b/src/providers/arcgisrest/qgsafsprovider.cpp
index 6604f65b592..6990b816f7e 100644
--- a/src/providers/arcgisrest/qgsafsprovider.cpp
+++ b/src/providers/arcgisrest/qgsafsprovider.cpp
@@ -161,7 +161,7 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
if ( it != mCache.end() )
{
f = it.value();
- return filterRect.isNull() || f.geometry()->intersects( filterRect );
+ return filterRect.isNull() || f.constGeometry()->intersects( filterRect );
}
// Determine attributes to fetch
@@ -237,14 +237,14 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
QgsAbstractGeometryV2* geometry = QgsArcGisRestUtils::parseEsriGeoJSON( geometryData, queryData["geometryType"].toString(),
QgsWKBTypes::hasM( mGeometryType ), QgsWKBTypes::hasZ( mGeometryType ) );
// Above might return 0, which is ok since in theory empty geometries are allowed
- feature.setGeometry( new QgsGeometry( geometry ) );
+ feature.setGeometry( QgsGeometry( geometry ) );
}
feature.setValid( true );
mCache.insert( feature.id(), feature );
}
f = mCache[id];
Q_ASSERT( f.isValid() );
- return filterRect.isNull() || ( f.geometry() && f.geometry()->intersects( filterRect ) );
+ return filterRect.isNull() || ( f.constGeometry() && f.constGeometry()->intersects( filterRect ) );
}
void QgsAfsProvider::setDataSourceUri( const QString &uri )
diff --git a/src/providers/arcgisrest/qgsamsprovider.cpp b/src/providers/arcgisrest/qgsamsprovider.cpp
index cf2c43e5985..525659a04d1 100644
--- a/src/providers/arcgisrest/qgsamsprovider.cpp
+++ b/src/providers/arcgisrest/qgsamsprovider.cpp
@@ -421,7 +421,7 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPoint & thePoint, Qgs
QgsCoordinateReferenceSystem crs;
QgsAbstractGeometryV2* geometry = QgsArcGisRestUtils::parseEsriGeoJSON( resultMap["geometry"].toMap(), resultMap["geometryType"].toString(), false, false, &crs );
QgsFeature feature( fields );
- feature.setGeometry( new QgsGeometry( geometry ) );
+ feature.setGeometry( QgsGeometry( geometry ) );
feature.setAttributes( featureAttributes );
feature.setValid( true );
QgsFeatureStore store( fields, crs );
diff --git a/src/providers/db2/qgsdb2featureiterator.cpp b/src/providers/db2/qgsdb2featureiterator.cpp
index bd07f352656..a46f2a514b8 100644
--- a/src/providers/db2/qgsdb2featureiterator.cpp
+++ b/src/providers/db2/qgsdb2featureiterator.cpp
@@ -358,19 +358,19 @@ bool QgsDb2FeatureIterator::fetchFeature( QgsFeature& feature )
{
unsigned char* db2data = new unsigned char[wkb_size + 1]; // allocate persistent storage
memcpy( db2data, ( unsigned char* )ar.data(), wkb_size + 1 );
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( db2data, wkb_size );
+ QgsGeometry g;
+ g.fromWkb( db2data, wkb_size );
feature.setGeometry( g );
}
else
{
QgsDebugMsg( "Geometry is empty" );
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
}
else
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
feature.setValid( true );
mFetchCount++;
diff --git a/src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp b/src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
index 55a45a55f18..3315c3110ac 100644
--- a/src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
+++ b/src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
@@ -335,7 +335,8 @@ bool QgsDelimitedTextFeatureIterator::nextFeatureInternal( QgsFeature& feature )
feature.setFields( mSource->mFields ); // allow name-based attribute lookups
feature.setFeatureId( fid );
feature.initAttributes( mSource->mFields.count() );
- feature.setGeometry( geom );
+ feature.setGeometry( geom ? *geom : QgsGeometry() );
+ delete geom;
// If we are testing subset expression, then need all attributes just in case.
// Could be more sophisticated, but probably not worth it!
diff --git a/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp b/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
index e25716e5bc3..44d7b198cb0 100644
--- a/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
+++ b/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
@@ -480,11 +480,8 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
{
QgsFeature f;
f.setFeatureId( mFile->recordId() );
- f.setGeometry( geom );
+ f.setGeometry( *geom );
mSpatialIndex->insertFeature( f );
- // Feature now has ownership of geometry, so set to null
- // here to avoid deleting twice.
- geom = nullptr;
}
}
else
@@ -539,7 +536,9 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
{
QgsFeature f;
f.setFeatureId( mFile->recordId() );
- f.setGeometry( QgsGeometry::fromPoint( pt ) );
+ QgsGeometry* g = QgsGeometry::fromPoint( pt );
+ f.setGeometry( *g );
+ delete g;
mSpatialIndex->insertFeature( f );
}
}
diff --git a/src/providers/gpx/qgsgpxfeatureiterator.cpp b/src/providers/gpx/qgsgpxfeatureiterator.cpp
index 5de86dc58e5..016aa097107 100644
--- a/src/providers/gpx/qgsgpxfeatureiterator.cpp
+++ b/src/providers/gpx/qgsgpxfeatureiterator.cpp
@@ -187,7 +187,9 @@ bool QgsGPXFeatureIterator::readWaypoint( const QgsWaypoint& wpt, QgsFeature& fe
// some wkb voodoo
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
- feature.setGeometry( readWaypointGeometry( wpt ) );
+ QgsGeometry* g = readWaypointGeometry( wpt );
+ feature.setGeometry( *g );
+ delete g;
}
feature.setFeatureId( wpt.id );
feature.setValid( true );
@@ -226,7 +228,8 @@ bool QgsGPXFeatureIterator::readRoute( const QgsRoute& rte, QgsFeature& feature
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
- feature.setGeometry( theGeometry );
+ feature.setGeometry( *theGeometry );
+ delete theGeometry;
}
else
{
@@ -268,7 +271,8 @@ bool QgsGPXFeatureIterator::readTrack( const QgsTrack& trk, QgsFeature& feature
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
- feature.setGeometry( theGeometry );
+ feature.setGeometry( *theGeometry );
+ delete theGeometry;
}
else
{
diff --git a/src/providers/grass/qgis.v.in.cpp b/src/providers/grass/qgis.v.in.cpp
index 5c95efe8589..88c3e579c20 100644
--- a/src/providers/grass/qgis.v.in.cpp
+++ b/src/providers/grass/qgis.v.in.cpp
@@ -402,7 +402,9 @@ int main( int argc, char **argv )
}
QgsPoint point( x, y );
QgsFeature feature( area );
- feature.setGeometry( QgsGeometry::fromPoint( point ) );
+ QgsGeometry* g = QgsGeometry::fromPoint( point );
+ feature.setGeometry( *g );
+ delete g;
feature.setValid( true );
centroids.insert( area, feature );
spatialIndex.insertFeature( feature );
diff --git a/src/providers/grass/qgsgrassfeatureiterator.cpp b/src/providers/grass/qgsgrassfeatureiterator.cpp
index 455aaa79b1a..5d18386b789 100644
--- a/src/providers/grass/qgsgrassfeatureiterator.cpp
+++ b/src/providers/grass/qgsgrassfeatureiterator.cpp
@@ -494,7 +494,7 @@ bool QgsGrassFeatureIterator::fetchFeature( QgsFeature& feature )
{
if ( oldGeometry )
{
- feature.setGeometry( new QgsGeometry( oldGeometry->clone() ) );
+ feature.setGeometry( QgsGeometry( oldGeometry->clone() ) );
}
else
{
@@ -618,7 +618,7 @@ void QgsGrassFeatureIterator::setFeatureGeometry( QgsFeature& feature, int id, i
{
QgsDebugMsg( QString( "unknown type = %1" ).arg( type ) );
}
- feature.setGeometry( new QgsGeometry( geometry ) );
+ feature.setGeometry( QgsGeometry( geometry ) );
}
QgsFeatureId QgsGrassFeatureIterator::makeFeatureId( int grassId, int cat, int layer )
diff --git a/src/providers/grass/qgsgrassimport.cpp b/src/providers/grass/qgsgrassimport.cpp
index 98a8b736bff..63de7a1fb9c 100644
--- a/src/providers/grass/qgsgrassimport.cpp
+++ b/src/providers/grass/qgsgrassimport.cpp
@@ -638,9 +638,11 @@ bool QgsGrassVectorImport::import()
{
continue;
}
- if ( doTransform && feature.geometry() )
+ if ( doTransform && feature.constGeometry() )
{
- feature.geometry()->transform( coordinateTransform );
+ QgsGeometry g = *feature.constGeometry();
+ g.transform( coordinateTransform );
+ feature.setGeometry( g );
}
if ( isCanceled() )
{
diff --git a/src/providers/grass/qgsgrassprovider.cpp b/src/providers/grass/qgsgrassprovider.cpp
index 7094a58bd13..2bbe6feba29 100644
--- a/src/providers/grass/qgsgrassprovider.cpp
+++ b/src/providers/grass/qgsgrassprovider.cpp
@@ -1112,7 +1112,7 @@ void QgsGrassProvider::startEditing( QgsVectorLayer *vectorLayer )
mEditBuffer = vectorLayer->editBuffer();
connect( mEditBuffer, SIGNAL( featureAdded( QgsFeatureId ) ), SLOT( onFeatureAdded( QgsFeatureId ) ) );
connect( mEditBuffer, SIGNAL( featureDeleted( QgsFeatureId ) ), SLOT( onFeatureDeleted( QgsFeatureId ) ) );
- connect( mEditBuffer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), SLOT( onGeometryChanged( QgsFeatureId, QgsGeometry & ) ) );
+ connect( mEditBuffer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), SLOT( onGeometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
connect( mEditBuffer, SIGNAL( attributeValueChanged( QgsFeatureId, int, const QVariant & ) ), SLOT( onAttributeValueChanged( QgsFeatureId, int, const QVariant & ) ) );
connect( mEditBuffer, SIGNAL( attributeAdded( int ) ), SLOT( onAttributeAdded( int ) ) );
connect( mEditBuffer, SIGNAL( attributeDeleted( int ) ), SLOT( onAttributeDeleted( int ) ) );
@@ -1254,11 +1254,11 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
QgsWKBTypes::Type wkbType = QgsWKBTypes::flatType( geometry->wkbType() );
if ( wkbType == QgsWKBTypes::Polygon )
{
- const QgsPolygonV2* polygon = dynamic_cast( addedFeatures[fid].geometry()->geometry() );
+ const QgsPolygonV2* polygon = dynamic_cast( addedFeatures[fid].constGeometry()->geometry() );
if ( polygon )
{
QgsLineStringV2* lineString = polygon->exteriorRing()->curveToLine();
- addedFeatures[fid].setGeometry( new QgsGeometry( lineString ) );
+ addedFeatures[fid].setGeometry( QgsGeometry( lineString ) );
}
// TODO: create also centroid and add it to undo
}
@@ -1660,7 +1660,7 @@ void QgsGrassProvider::onFeatureDeleted( QgsFeatureId fid )
}
}
-void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )
+void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
{
int oldLid = QgsGrassFeatureIterator::lidFromFid( fid );
int realLine = oldLid;
diff --git a/src/providers/grass/qgsgrassprovider.h b/src/providers/grass/qgsgrassprovider.h
index 1cb6baf3d7d..dc11f51f669 100644
--- a/src/providers/grass/qgsgrassprovider.h
+++ b/src/providers/grass/qgsgrassprovider.h
@@ -374,7 +374,7 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
public slots:
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
- void onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom );
+ void onGeometryChanged( QgsFeatureId fid, const QgsGeometry& geom );
void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
void onAttributeAdded( int idx );
void onAttributeDeleted( int idx );
diff --git a/src/providers/mssql/qgsmssqlfeatureiterator.cpp b/src/providers/mssql/qgsmssqlfeatureiterator.cpp
index 495ef2ee1be..a3567cca468 100644
--- a/src/providers/mssql/qgsmssqlfeatureiterator.cpp
+++ b/src/providers/mssql/qgsmssqlfeatureiterator.cpp
@@ -314,18 +314,18 @@ bool QgsMssqlFeatureIterator::fetchFeature( QgsFeature& feature )
unsigned char* wkb = mParser.ParseSqlGeometry(( unsigned char* )ar.data(), ar.size() );
if ( wkb )
{
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( wkb, mParser.GetWkbLen() );
+ QgsGeometry g;
+ g.fromWkb( wkb, mParser.GetWkbLen() );
feature.setGeometry( g );
}
else
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
}
else
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
feature.setValid( true );
diff --git a/src/providers/ogr/qgsogrfeatureiterator.cpp b/src/providers/ogr/qgsogrfeatureiterator.cpp
index 26e8cebf209..9b44b3cd269 100644
--- a/src/providers/ogr/qgsogrfeatureiterator.cpp
+++ b/src/providers/ogr/qgsogrfeatureiterator.cpp
@@ -281,7 +281,7 @@ bool QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
feature.setGeometry( QgsOgrUtils::ogrGeometryToQgsGeometry( geom ) );
}
else
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
if (( useIntersect && ( !feature.constGeometry() || !feature.constGeometry()->intersects( mRequest.filterRect() ) ) )
|| ( geometryTypeFilter && ( !feature.constGeometry() || QgsOgrProvider::ogrWkbSingleFlatten(( OGRwkbGeometryType )feature.constGeometry()->wkbType() ) != mSource->mOgrGeometryTypeFilter ) ) )
@@ -293,7 +293,7 @@ bool QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
if ( !mFetchGeometry )
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
// fetch attributes
diff --git a/src/providers/oracle/qgsoraclefeatureiterator.cpp b/src/providers/oracle/qgsoraclefeatureiterator.cpp
index c456a983f43..9d150217fac 100644
--- a/src/providers/oracle/qgsoraclefeatureiterator.cpp
+++ b/src/providers/oracle/qgsoraclefeatureiterator.cpp
@@ -244,7 +244,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
for ( ;; )
{
feature.initAttributes( mSource->mFields.count() );
- feature.setGeometry( 0 );
+ feature.setGeometry( QgsGeometry() );
if ( mRewind )
{
@@ -273,18 +273,18 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
unsigned char *copy = new unsigned char[ba->size()];
memcpy( copy, ba->constData(), ba->size() );
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( copy, ba->size() );
+ QgsGeometry g;
+ g.fromWkb( copy, ba->size() );
feature.setGeometry( g );
}
else
{
- feature.setGeometry( 0 );
+ feature.setGeometry( QgsGeometry() );
}
if ( !mRequest.filterRect().isNull() )
{
- if ( !feature.geometry() )
+ if ( !feature.constGeometry() )
{
QgsDebugMsg( "no geometry to intersect" );
continue;
@@ -296,7 +296,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
if ( !mSource->mHasSpatialIndex )
{
// only intersect with bbox
- if ( !feature.geometry()->boundingBox().intersects( mRequest.filterRect() ) )
+ if ( !feature.constGeometry()->boundingBox().intersects( mRequest.filterRect() ) )
{
// skip feature that don't intersect with our rectangle
QgsDebugMsg( "no bbox intersect" );
@@ -307,7 +307,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
else if ( !mConnection->hasSpatial() || !mSource->mHasSpatialIndex )
{
// couldn't use sdo_relate earlier
- if ( !feature.geometry()->intersects( mRequest.filterRect() ) )
+ if ( !feature.constGeometry()->intersects( mRequest.filterRect() ) )
{
// skip feature that don't intersect with our rectangle
QgsDebugMsg( "no exact intersect" );
diff --git a/src/providers/oracle/qgsoracleprovider.cpp b/src/providers/oracle/qgsoracleprovider.cpp
index 7816f6728bb..068eb0bfb6f 100644
--- a/src/providers/oracle/qgsoracleprovider.cpp
+++ b/src/providers/oracle/qgsoracleprovider.cpp
@@ -1329,7 +1329,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
if ( !mGeometryColumn.isNull() )
{
- appendGeomParam( features->geometry(), ins );
+ appendGeomParam( features->constGeometry(), ins );
}
for ( int i = 0; i < fieldId.size(); i++ )
diff --git a/src/providers/postgres/qgspostgresfeatureiterator.cpp b/src/providers/postgres/qgspostgresfeatureiterator.cpp
index a7022f12076..84f073f8d88 100644
--- a/src/providers/postgres/qgspostgresfeatureiterator.cpp
+++ b/src/providers/postgres/qgspostgresfeatureiterator.cpp
@@ -691,13 +691,13 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
}
}
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( featureGeom, returnedLength + 1 );
+ QgsGeometry g;
+ g.fromWkb( featureGeom, returnedLength + 1 );
feature.setGeometry( g );
}
else
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
col++;
diff --git a/src/providers/spatialite/qgsspatialitefeatureiterator.cpp b/src/providers/spatialite/qgsspatialitefeatureiterator.cpp
index c4d1aafe2c5..cb8538d4043 100644
--- a/src/providers/spatialite/qgsspatialitefeatureiterator.cpp
+++ b/src/providers/spatialite/qgsspatialitefeatureiterator.cpp
@@ -463,7 +463,7 @@ bool QgsSpatiaLiteFeatureIterator::getFeature( sqlite3_stmt *stmt, QgsFeature &f
if ( !mFetchGeometry )
{
// no geometry was required
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
feature.initAttributes( mSource->mFields.count() );
@@ -558,17 +558,17 @@ void QgsSpatiaLiteFeatureIterator::getFeatureGeometry( sqlite3_stmt* stmt, int i
QgsSpatiaLiteProvider::convertToGeosWKB(( const unsigned char * )blob, blob_size, &featureGeom, &geom_size );
if ( featureGeom )
{
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( featureGeom, geom_size );
+ QgsGeometry g;
+ g.fromWkb( featureGeom, geom_size );
feature.setGeometry( g );
}
else
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
else
{
// NULL geometry
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
}
diff --git a/src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp b/src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
index 7a3bb571a7a..f45a5941c08 100644
--- a/src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
+++ b/src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
@@ -232,7 +232,7 @@ bool QgsVirtualLayerFeatureIterator::fetchFeature( QgsFeature& feature )
}
else
{
- feature.setGeometry( nullptr );
+ feature.setGeometry( QgsGeometry() );
}
}
diff --git a/src/providers/virtual/qgsvirtuallayerprovider.cpp b/src/providers/virtual/qgsvirtuallayerprovider.cpp
index dca83174c48..56d6119d631 100644
--- a/src/providers/virtual/qgsvirtuallayerprovider.cpp
+++ b/src/providers/virtual/qgsvirtuallayerprovider.cpp
@@ -120,7 +120,7 @@ bool QgsVirtualLayerProvider::loadSourceLayers()
// connect to modification signals to invalidate statistics
connect( vl, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( invalidateStatistics() ) );
connect( vl, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( invalidateStatistics() ) );
- connect( vl, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( invalidateStatistics() ) );
+ connect( vl, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry& ) ), this, SLOT( invalidateStatistics() ) );
}
else
{
diff --git a/src/providers/wfs/qgswfsfeatureiterator.cpp b/src/providers/wfs/qgswfsfeatureiterator.cpp
index 382fb04198b..350edc13517 100644
--- a/src/providers/wfs/qgswfsfeatureiterator.cpp
+++ b/src/providers/wfs/qgswfsfeatureiterator.cpp
@@ -590,9 +590,11 @@ void QgsWFSFeatureDownloader::run( bool serializeFeatures, int maxFeatures )
QgsDebugMsg( "Server does not seem to properly support paging since it returned the same first feature for 2 different page requests. Disabling paging" );
}
- if ( mShared->mGetFeatureEPSGDotHonoursEPSGOrder && f.geometry() )
+ if ( mShared->mGetFeatureEPSGDotHonoursEPSGOrder && f.constGeometry() )
{
- f.geometry()->transform( QTransform( 0, 1, 1, 0, 0, 0 ) );
+ QgsGeometry g = *f.constGeometry();
+ g.transform( QTransform( 0, 1, 1, 0, 0, 0 ) );
+ f.setGeometry( g );
}
featureList.push_back( QgsWFSFeatureGmlIdPair( f, gmlId ) );
@@ -960,29 +962,29 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature& f )
if ( !v.isNull() && v.type() == QVariant::String )
{
QByteArray wkbGeom( QByteArray::fromHex( v.toString().toAscii() ) );
- QgsGeometry *g = new QgsGeometry();
+ QgsGeometry g;
unsigned char* wkbClone = new unsigned char[wkbGeom.size()];
memcpy( wkbClone, wkbGeom.data(), wkbGeom.size() );
try
{
- g->fromWkb( wkbClone, wkbGeom.size() );
+ g.fromWkb( wkbClone, wkbGeom.size() );
cachedFeature.setGeometry( g );
}
catch ( const QgsWkbException& )
{
QgsDebugMsg( QString( "Invalid WKB for cached feature %1" ).arg( cachedFeature.id() ) );
delete[] wkbClone;
- cachedFeature.setGeometry( nullptr );
+ cachedFeature.setGeometry( QgsGeometry() );
}
}
else
{
- cachedFeature.setGeometry( nullptr );
+ cachedFeature.setGeometry( QgsGeometry() );
}
}
else
{
- cachedFeature.setGeometry( nullptr );
+ cachedFeature.setGeometry( QgsGeometry() );
}
const QgsGeometry* constGeom = cachedFeature.constGeometry();
@@ -1164,13 +1166,13 @@ void QgsWFSFeatureIterator::copyFeature( const QgsFeature& srcFeature, QgsFeatur
unsigned char* copiedGeom = new unsigned char[geomSize];
memcpy( copiedGeom, geom, geomSize );
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( copiedGeom, geomSize );
+ QgsGeometry g;
+ g.fromWkb( copiedGeom, geomSize );
dstFeature.setGeometry( g );
}
else
{
- dstFeature.setGeometry( nullptr );
+ dstFeature.setGeometry( QgsGeometry() );
}
//and the attributes
diff --git a/src/providers/wfs/qgswfsshareddata.cpp b/src/providers/wfs/qgswfsshareddata.cpp
index efcbf6a287d..adb91cca953 100644
--- a/src/providers/wfs/qgswfsshareddata.cpp
+++ b/src/providers/wfs/qgswfsshareddata.cpp
@@ -516,7 +516,7 @@ int QgsWFSSharedData::registerToCache( QgsWFSFeatureIterator* iterator, QgsRecta
// If the requested bbox is inside an already cached rect that didn't
// hit the download limit, then we can reuse the cached features without
// issuing a new request.
- if ( mRegions[id].geometry()->boundingBox().contains( rect ) &&
+ if ( mRegions[id].constGeometry()->boundingBox().contains( rect ) &&
!mRegions[id].attributes().value( 0 ).toBool() )
{
QgsDebugMsg( "Cached features already cover this area of interest" );
@@ -527,7 +527,7 @@ int QgsWFSSharedData::registerToCache( QgsWFSFeatureIterator* iterator, QgsRecta
// On the other hand, if the requested bbox is inside an already cached rect,
// that hit the download limit, our larger bbox will hit it too, so no need
// to re-issue a new request either.
- if ( rect.contains( mRegions[id].geometry()->boundingBox() ) &&
+ if ( rect.contains( mRegions[id].constGeometry()->boundingBox() ) &&
mRegions[id].attributes().value( 0 ).toBool() )
{
QgsDebugMsg( "Current request is larger than a smaller request that hit the download limit, so no server download needed." );
@@ -884,7 +884,8 @@ void QgsWFSSharedData::serializeFeatures( QVector& featu
else
localComputedExtent.combineExtentWith( bBox );
QgsGeometry* polyBoundingBox = QgsGeometry::fromRect( bBox );
- cachedFeature.setGeometry( polyBoundingBox );
+ cachedFeature.setGeometry( *polyBoundingBox );
+ delete polyBoundingBox;
}
else
{
@@ -1037,7 +1038,9 @@ void QgsWFSSharedData::endOfDownload( bool success, int featureCount,
// In case the download was successful, we will remember this bbox
// and if the download reached the download limit or not
QgsFeature f;
- f.setGeometry( QgsGeometry::fromRect( mRect ) );
+ QgsGeometry* g = QgsGeometry::fromRect( mRect );
+ f.setGeometry( *g );
+ delete g;
QgsFeatureId id = mRegions.size();
f.setFeatureId( id );
f.initAttributes( 1 );
diff --git a/src/providers/wms/qgswmsprovider.cpp b/src/providers/wms/qgswmsprovider.cpp
index 12fc3711a76..72fbac1b355 100644
--- a/src/providers/wms/qgswmsprovider.cpp
+++ b/src/providers/wms/qgswmsprovider.cpp
@@ -2631,7 +2631,9 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
if ( coordinateTransform.isValid() && feature->constGeometry() )
{
- feature->geometry()->transform( coordinateTransform );
+ QgsGeometry g = *feature->constGeometry();
+ g.transform( coordinateTransform );
+ feature->setGeometry( g );
}
featureStore.features().append( QgsFeature( *feature ) );
}
@@ -2737,13 +2739,15 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
OGR_G_ExportToWkb( ogrGeom, ( OGRwkbByteOrder ) QgsApplication::endian(), wkb );
OGR_G_DestroyGeometry( ogrGeom );
- QgsGeometry *g = new QgsGeometry();
- g->fromWkb( wkb, wkbSize );
+ QgsGeometry g;
+ g.fromWkb( wkb, wkbSize );
feature.setGeometry( g );
if ( coordinateTransform.isValid() && feature.constGeometry() )
{
- feature.geometry()->transform( coordinateTransform );
+ QgsGeometry transformed = *feature.constGeometry();
+ transformed.transform( coordinateTransform );
+ feature.setGeometry( transformed );
}
}
}
diff --git a/src/server/qgswfsserver.cpp b/src/server/qgswfsserver.cpp
index 762a491c5e8..fa8e8f62adf 100644
--- a/src/server/qgswfsserver.cpp
+++ b/src/server/qgswfsserver.cpp
@@ -1616,8 +1616,13 @@ QDomDocument QgsWfsServer::transaction( const QString& requestBody )
if ( !geometryElem.isNull() )
{
- if ( !layer->changeGeometry( *fidIt, QgsOgcUtils::geometryFromGML( geometryElem ) ) )
+ QgsGeometry* g = QgsOgcUtils::geometryFromGML( geometryElem );
+ if ( !layer->changeGeometry( *fidIt, *g ) )
+ {
+ delete g;
throw QgsMapServiceException( "RequestNotWellFormed", "Error in change geometry" );
+ }
+ delete g;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -1752,7 +1757,9 @@ QDomDocument QgsWfsServer::transaction( const QString& requestBody )
}
else //a geometry attribute
{
- inFeatList.last().setGeometry( QgsOgcUtils::geometryFromGML( currentAttributeElement ) );
+ QgsGeometry* g = QgsOgcUtils::geometryFromGML( currentAttributeElement );
+ inFeatList.last().setGeometry( *g );
+ delete g;
}
}
currentAttributeChild = currentAttributeChild.nextSibling();
@@ -1887,12 +1894,14 @@ QString QgsWfsServer::createFeatureGeoJSON( QgsFeature* feat, int prec, QgsCoord
{
QgsRectangle box = geom->boundingBox();
QgsGeometry* bbox = QgsGeometry::fromRect( box );
- f.setGeometry( bbox );
+ f.setGeometry( *bbox );
+ delete bbox;
}
else if ( mGeometryName == "CENTROID" )
{
QgsGeometry* centroid = geom->centroid();
- f.setGeometry( centroid );
+ f.setGeometry( *centroid );
+ delete centroid;
}
}
diff --git a/src/server/qgswmsconfigparser.cpp b/src/server/qgswmsconfigparser.cpp
index 048b4b53b4c..7867f63df62 100644
--- a/src/server/qgswmsconfigparser.cpp
+++ b/src/server/qgswmsconfigparser.cpp
@@ -465,7 +465,8 @@ QgsVectorLayer* QgsWmsConfigParser::createHighlightLayer( int i, const QString&
layer->setCustomProperty( "labeling/placement", placement );
}
- fet.setGeometry( geom );
+ fet.setGeometry( *geom );
+ delete geom;
layer->dataProvider()->addFeatures( QgsFeatureList() << fet );
return layer;
}
diff --git a/src/server/qgswmsserver.cpp b/src/server/qgswmsserver.cpp
index f41b660ce87..5b298a82375 100644
--- a/src/server/qgswmsserver.cpp
+++ b/src/server/qgswmsserver.cpp
@@ -2359,18 +2359,18 @@ int QgsWmsServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
//also append the wkt geometry as an attribute
if ( addWktGeometry && hasGeometry )
{
- QgsGeometry *geom = feature.geometry();
- if ( geom )
+ QgsGeometry geom = feature.constGeometry() ? *feature.constGeometry() : QgsGeometry();
+ if ( !geom.isEmpty() )
{
if ( layer->crs() != outputCrs )
{
QgsCoordinateTransform transform = mapRender->transformation( layer );
if ( transform.isValid() )
- geom->transform( transform );
+ geom.transform( transform );
}
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
geometryElement.setAttribute( "name", "geometry" );
- geometryElement.setAttribute( "value", geom->exportToWkt( getWMSPrecision( 8 ) ) );
+ geometryElement.setAttribute( "value", geom.exportToWkt( getWMSPrecision( 8 ) ) );
geometryElement.setAttribute( "type", "derived" );
featureElement.appendChild( geometryElement );
}
@@ -3198,7 +3198,7 @@ QDomElement QgsWmsServer::createFeatureGML(
transform = mMapRenderer->transformation( layer );
}
- QgsGeometry* geom = feat->geometry();
+ QgsGeometry geom = feat->constGeometry() ? *feat->constGeometry() : QgsGeometry();
QgsExpressionContext expressionContext;
expressionContext << QgsExpressionContextUtils::globalScope()
@@ -3208,7 +3208,7 @@ QDomElement QgsWmsServer::createFeatureGML(
expressionContext.setFeature( *feat );
// always add bounding box info if feature contains geometry
- if ( geom && geom->type() != Qgis::UnknownGeometry && geom->type() != Qgis::NoGeometry )
+ if ( !geom.isEmpty() && geom.type() != Qgis::UnknownGeometry && geom.type() != Qgis::NoGeometry )
{
QgsRectangle box = feat->constGeometry()->boundingBox();
if ( transform.isValid() )
@@ -3243,24 +3243,24 @@ QDomElement QgsWmsServer::createFeatureGML(
typeNameElement.appendChild( bbElem );
}
- if ( withGeom && geom )
+ if ( withGeom && !geom.isEmpty() )
{
//add geometry column (as gml)
if ( transform.isValid() )
{
- geom->transform( transform );
+ geom.transform( transform );
}
QDomElement geomElem = doc.createElement( "qgs:geometry" );
QDomElement gmlElem;
if ( version < 3 )
{
- gmlElem = QgsOgcUtils::geometryToGML( geom, doc, 8 );
+ gmlElem = QgsOgcUtils::geometryToGML( &geom, doc, 8 );
}
else
{
- gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3", 8 );
+ gmlElem = QgsOgcUtils::geometryToGML( &geom, doc, "GML3", 8 );
}
if ( !gmlElem.isNull() )
diff --git a/tests/src/app/testqgisappclipboard.cpp b/tests/src/app/testqgisappclipboard.cpp
index 3d0740ea8c0..3c3ad82134f 100644
--- a/tests/src/app/testqgisappclipboard.cpp
+++ b/tests/src/app/testqgisappclipboard.cpp
@@ -129,11 +129,11 @@ void TestQgisAppClipboard::copyToText()
QgsFeature feat( fields, 5 );
feat.setAttribute( "int_field", 9 );
feat.setAttribute( "string_field", "val" );
- feat.setGeometry( new QgsGeometry( new QgsPointV2( 5, 6 ) ) );
+ feat.setGeometry( QgsGeometry( new QgsPointV2( 5, 6 ) ) );
QgsFeature feat2( fields, 6 );
feat2.setAttribute( "int_field", 19 );
feat2.setAttribute( "string_field", "val2" );
- feat2.setGeometry( new QgsGeometry( new QgsPointV2( 7, 8 ) ) );
+ feat2.setGeometry( QgsGeometry( new QgsPointV2( 7, 8 ) ) );
QgsFeatureStore feats;
feats.addFeature( feat );
feats.addFeature( feat2 );
@@ -179,7 +179,7 @@ void TestQgisAppClipboard::copyToText()
QgsCoordinateReferenceSystem crs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
feats = QgsFeatureStore();
feats.setCrs( crs );
- feat.setGeometry( new QgsGeometry( new QgsPointV2( 2502577, 2403869 ) ) );
+ feat.setGeometry( QgsGeometry( new QgsPointV2( 2502577, 2403869 ) ) );
feats.addFeature( feat );
feats.setFields( fields );
mQgisApp->clipboard()->replaceWithCopyOf( feats );
diff --git a/tests/src/app/testqgsattributetable.cpp b/tests/src/app/testqgsattributetable.cpp
index de434957821..364f1d477e6 100644
--- a/tests/src/app/testqgsattributetable.cpp
+++ b/tests/src/app/testqgsattributetable.cpp
@@ -80,7 +80,9 @@ void TestQgsAttributeTable::testFieldCalculation()
f1.setAttribute( "col1", 0.0 );
QgsPolyline line3111;
line3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 );
- f1.setGeometry( QgsGeometry::fromPolyline( line3111 ) );
+ QgsGeometry* line3111G = QgsGeometry::fromPolyline( line3111 ) ;
+ f1.setGeometry( *line3111G );
+ delete line3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
@@ -132,7 +134,9 @@ void TestQgsAttributeTable::testFieldCalculationArea()
polygonRing3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 ) << QgsPoint( 2520109, 2397715 ) << QgsPoint( 2520792, 2425494 ) << QgsPoint( 2484588, 2425722 );
QgsPolygon polygon3111;
polygon3111 << polygonRing3111;
- f1.setGeometry( QgsGeometry::fromPolygon( polygon3111 ) );
+ QgsGeometry* polygon3111G = QgsGeometry::fromPolygon( polygon3111 );
+ f1.setGeometry( *polygon3111G );
+ delete polygon3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
diff --git a/tests/src/app/testqgsfieldcalculator.cpp b/tests/src/app/testqgsfieldcalculator.cpp
index 76598471c2f..efe2b5f2e92 100644
--- a/tests/src/app/testqgsfieldcalculator.cpp
+++ b/tests/src/app/testqgsfieldcalculator.cpp
@@ -80,7 +80,9 @@ void TestQgsFieldCalculator::testLengthCalculations()
f1.setAttribute( "col1", 0.0 );
QgsPolyline line3111;
line3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 );
- f1.setGeometry( QgsGeometry::fromPolyline( line3111 ) );
+ QgsGeometry* line3111G = QgsGeometry::fromPolyline( line3111 ) ;
+ f1.setGeometry( *line3111G );
+ delete line3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
@@ -143,7 +145,9 @@ void TestQgsFieldCalculator::testAreaCalculations()
polygonRing3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 ) << QgsPoint( 2520109, 2397715 ) << QgsPoint( 2520792, 2425494 ) << QgsPoint( 2484588, 2425722 );
QgsPolygon polygon3111;
polygon3111 << polygonRing3111;
- f1.setGeometry( QgsGeometry::fromPolygon( polygon3111 ) );
+ QgsGeometry* polygon3111G = QgsGeometry::fromPolygon( polygon3111 ) ;
+ f1.setGeometry( *polygon3111G );
+ delete polygon3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
diff --git a/tests/src/app/testqgsmaptoolidentifyaction.cpp b/tests/src/app/testqgsmaptoolidentifyaction.cpp
index 7a8f224e603..e4adbee44d3 100644
--- a/tests/src/app/testqgsmaptoolidentifyaction.cpp
+++ b/tests/src/app/testqgsmaptoolidentifyaction.cpp
@@ -121,14 +121,16 @@ void TestQgsMapToolIdentifyAction::lengthCalculation()
f1.setAttribute( "col1", 0.0 );
QgsPolyline line3111;
line3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 );
- f1.setGeometry( QgsGeometry::fromPolyline( line3111 ) );
+ QgsGeometry* line3111G = QgsGeometry::fromPolyline( line3111 ) ;
+ f1.setGeometry( *line3111G );
+ delete line3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
canvas->setCrsTransformEnabled( true );
canvas->setDestinationCrs( srs );
- canvas->setExtent( f1.geometry()->boundingBox() );
+ canvas->setExtent( f1.constGeometry()->boundingBox() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSID", ( int ) srs.srsid() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCrs", srs.authid() );
@@ -176,14 +178,16 @@ void TestQgsMapToolIdentifyAction::perimeterCalculation()
polygonRing3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 ) << QgsPoint( 2520109, 2397715 ) << QgsPoint( 2520792, 2425494 ) << QgsPoint( 2484588, 2425722 );
QgsPolygon polygon3111;
polygon3111 << polygonRing3111;
- f1.setGeometry( QgsGeometry::fromPolygon( polygon3111 ) );
+ QgsGeometry* polygon3111G = QgsGeometry::fromPolygon( polygon3111 ) ;
+ f1.setGeometry( *polygon3111G );
+ delete polygon3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
canvas->setCrsTransformEnabled( true );
canvas->setDestinationCrs( srs );
- canvas->setExtent( f1.geometry()->boundingBox() );
+ canvas->setExtent( f1.constGeometry()->boundingBox() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSID", ( int ) srs.srsid() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCrs", srs.authid() );
@@ -232,14 +236,16 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
polygonRing3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 ) << QgsPoint( 2520109, 2397715 ) << QgsPoint( 2520792, 2425494 ) << QgsPoint( 2484588, 2425722 );
QgsPolygon polygon3111;
polygon3111 << polygonRing3111;
- f1.setGeometry( QgsGeometry::fromPolygon( polygon3111 ) );
+ QgsGeometry* polygon3111G = QgsGeometry::fromPolygon( polygon3111 ) ;
+ f1.setGeometry( *polygon3111G );
+ delete polygon3111G;
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
canvas->setCrsTransformEnabled( true );
canvas->setDestinationCrs( srs );
- canvas->setExtent( f1.geometry()->boundingBox() );
+ canvas->setExtent( f1.constGeometry()->boundingBox() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSID", ( int ) srs.srsid() );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCrs", srs.authid() );
diff --git a/tests/src/core/testqgsconnectionpool.cpp b/tests/src/core/testqgsconnectionpool.cpp
index 5450a206596..449217baa7e 100644
--- a/tests/src/core/testqgsconnectionpool.cpp
+++ b/tests/src/core/testqgsconnectionpool.cpp
@@ -115,14 +115,14 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX()
for ( int i = 0, n = layer1Features.count(); i < n; ++i )
{
- const QgsPointV2* geom = dynamic_cast( layer1Features[i].geometry()->geometry() );
+ const QgsPointV2* geom = dynamic_cast( layer1Features[i].constGeometry()->geometry() );
QVERIFY( geom != nullptr );
QVERIFY( qFuzzyCompare( geom->x(), i ) );
QVERIFY( qFuzzyCompare( geom->y(), i ) );
}
for ( int i = 0, n = layer2Features.count(); i < n; ++i )
{
- const QgsLineStringV2* geom = dynamic_cast( layer2Features[i].geometry()->geometry() );
+ const QgsLineStringV2* geom = dynamic_cast( layer2Features[i].constGeometry()->geometry() );
QVERIFY( geom != nullptr );
int nVtx = geom->vertexCount();
QVERIFY( nVtx == nRoutePts );
diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp
index 8f550be812f..f3c9b3d320d 100644
--- a/tests/src/core/testqgsexpression.cpp
+++ b/tests/src/core/testqgsexpression.cpp
@@ -1561,7 +1561,8 @@ class TestQgsExpression: public QObject
QgsGeometry* geom = ( QgsGeometry* ) geomptr;
QgsFeature f;
- f.setGeometry( geom );
+ f.setGeometry( *geom );
+ delete geom;
QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
@@ -1586,8 +1587,12 @@ class TestQgsExpression: public QObject
QgsPolygon polygon;
polygon << polygon_ring;
QgsFeature fPolygon, fPolyline;
- fPolyline.setGeometry( QgsGeometry::fromPolyline( polyline ) );
- fPolygon.setGeometry( QgsGeometry::fromPolygon( polygon ) );
+ QgsGeometry* polylineGeom = QgsGeometry::fromPolyline( polyline );
+ fPolyline.setGeometry( *polylineGeom );
+ delete polylineGeom;
+ QgsGeometry* polygonGeom = QgsGeometry::fromPolygon( polygon );
+ fPolygon.setGeometry( *polygonGeom );
+ delete polygonGeom;
QgsExpressionContext context;
@@ -1746,7 +1751,9 @@ class TestQgsExpression: public QObject
polygonRing3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 ) << QgsPoint( 2520109, 2397715 ) << QgsPoint( 2520792, 2425494 ) << QgsPoint( 2484588, 2425722 );
QgsPolygon polygon3111;
polygon3111 << polygonRing3111;
- feat.setGeometry( QgsGeometry::fromPolygon( polygon3111 ) );
+ QgsGeometry* polygon3111G = QgsGeometry::fromPolygon( polygon3111 );
+ feat.setGeometry( *polygon3111G );
+ delete polygon3111G;
QgsExpressionContext context;
context.setFeature( feat );
@@ -1815,7 +1822,9 @@ class TestQgsExpression: public QObject
// test length without geomCalculator
QgsPolyline line3111;
line3111 << QgsPoint( 2484588, 2425722 ) << QgsPoint( 2482767, 2398853 );
- feat.setGeometry( QgsGeometry::fromPolyline( line3111 ) );
+ QgsGeometry* line3111G = QgsGeometry::fromPolyline( line3111 ) ;
+ feat.setGeometry( *line3111G );
+ delete line3111G;
context.setFeature( feat );
QgsExpression expLength( "$length" );
@@ -1859,9 +1868,15 @@ class TestQgsExpression: public QObject
polygon << polygon_ring;
QgsFeature fPoint, fPolygon, fPolyline;
- fPoint.setGeometry( QgsGeometry::fromPoint( QgsPoint( -1.23456789, 9.87654321 ) ) );
- fPolyline.setGeometry( QgsGeometry::fromPolyline( polyline ) );
- fPolygon.setGeometry( QgsGeometry::fromPolygon( polygon ) );
+ QgsGeometry* fPointG = QgsGeometry::fromPoint( QgsPoint( -1.23456789, 9.87654321 ) );
+ fPoint.setGeometry( *fPointG );
+ delete fPointG;
+ QgsGeometry* fPolylineG = QgsGeometry::fromPolyline( polyline );
+ fPolyline.setGeometry( *fPolylineG );
+ delete fPolylineG;
+ QgsGeometry* fPolygonG = QgsGeometry::fromPolygon( polygon );
+ fPolygon.setGeometry( *fPolygonG );
+ delete fPolygonG;
QgsExpressionContext context;
@@ -1950,7 +1965,7 @@ class TestQgsExpression: public QObject
QgsGeometry* geom = ( QgsGeometry* ) geomptr;
QgsFeature f;
- f.setGeometry( geom );
+ f.setGeometry( *geom );
QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
@@ -1974,6 +1989,8 @@ class TestQgsExpression: public QObject
QCOMPARE( out.canConvert(), true );
outGeom = out.value();
QCOMPARE( geom->equals( &outGeom ), true );
+
+ delete geom;
}
void eval_geometry_access_transform_data()
@@ -2027,7 +2044,7 @@ class TestQgsExpression: public QObject
QgsGeometry* geom = ( QgsGeometry* ) geomptr;
QgsFeature f;
- f.setGeometry( geom );
+ f.setGeometry( *geom );
QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
@@ -2050,6 +2067,8 @@ class TestQgsExpression: public QObject
QCOMPARE( out.canConvert(), true );
outGeom = out.value();
QCOMPARE( geom->equals( &outGeom ), true );
+
+ delete geom;
}
void eval_spatial_operator_data()
@@ -2098,7 +2117,7 @@ class TestQgsExpression: public QObject
QgsGeometry* geom = ( QgsGeometry* ) geomptr;
QgsFeature f;
- f.setGeometry( geom );
+ f.setGeometry( *geom );
QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
@@ -2115,6 +2134,8 @@ class TestQgsExpression: public QObject
out = exp.evaluate( &context );
QCOMPARE( exp.hasEvalError(), evalError );
QCOMPARE( out.toInt(), result.toInt() );
+
+ delete geom;
}
void eval_geometry_method_data()
@@ -2180,7 +2201,7 @@ class TestQgsExpression: public QObject
QgsGeometry *result = ( QgsGeometry * ) resultptr;
QgsFeature f;
- f.setGeometry( geom );
+ f.setGeometry( *geom );
QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
@@ -2206,6 +2227,7 @@ class TestQgsExpression: public QObject
QVERIFY( compareWkt( outGeom.exportToWkt(), result->exportToWkt() ) );
delete result;
+ delete geom;
}
void eval_special_columns()
diff --git a/tests/src/core/testqgsfeature.cpp b/tests/src/core/testqgsfeature.cpp
index 4284ce2606e..33b883e405f 100644
--- a/tests/src/core/testqgsfeature.cpp
+++ b/tests/src/core/testqgsfeature.cpp
@@ -246,20 +246,20 @@ void TestQgsFeature::geometry()
{
QgsFeature feature;
//test no double delete of geometry when setting:
- feature.setGeometry( new QgsGeometry( *mGeometry2.data() ) );
- feature.setGeometry( new QgsGeometry( *mGeometry.data() ) );
+ feature.setGeometry( QgsGeometry( *mGeometry2.data() ) );
+ feature.setGeometry( QgsGeometry( *mGeometry.data() ) );
QCOMPARE( *feature.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
//test implicit sharing detachment
QgsFeature copy( feature );
QCOMPARE( *copy.constGeometry()->asWkb(), *feature.constGeometry()->asWkb() );
- copy.setGeometry( 0 );
+ copy.setGeometry( QgsGeometry() );
QVERIFY( ! copy.constGeometry() );
QCOMPARE( *feature.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
//test no crash when setting an empty geometry and triggering a detach
QgsFeature emptyGeomFeature;
- emptyGeomFeature.setGeometry( 0 );
+ emptyGeomFeature.setGeometry( QgsGeometry() );
copy = emptyGeomFeature;
copy.setFeatureId( 5 ); //force detach
@@ -267,19 +267,10 @@ void TestQgsFeature::geometry()
//always start with a copy so that we can test implicit sharing detachment is working
copy = feature;
QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
- copy.setGeometry( new QgsGeometry( *mGeometry2.data() ) );
+ copy.setGeometry( QgsGeometry( *mGeometry2.data() ) );
QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry2.data()->asWkb() );
QCOMPARE( *feature.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
- //test that non-const geometry triggers a detach
- copy = feature;
- QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
- copy.geometry()->convertToType( Qgis::Line );
- QScopedPointer expected( new QgsGeometry( *mGeometry.data() ) );
- expected->convertToType( Qgis::Line );
- QCOMPARE( *copy.constGeometry()->asWkb(), *expected->asWkb() );
- QCOMPARE( *feature.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
-
//setGeometry using reference
copy = feature;
QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
@@ -287,28 +278,6 @@ void TestQgsFeature::geometry()
copy.setGeometry( geomByRef );
QCOMPARE( *copy.constGeometry()->asWkb(), *geomByRef.asWkb() );
QCOMPARE( *feature.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
-
- //setGeometryAndOwnership
- Q_NOWARN_DEPRECATED_PUSH
- copy = feature;
- QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
- int wkbSize = mGeometry2->wkbSize();
- unsigned char* wkb = new unsigned char[wkbSize];
- memcpy( wkb, mGeometry2->asWkb(), wkbSize );
- copy.setGeometryAndOwnership( wkb, wkbSize );
- QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry2->asWkb() );
- QCOMPARE( *feature.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
-
- //geometryAndOwnership
- copy = feature;
- QCOMPARE( *copy.constGeometry()->asWkb(), *mGeometry.data()->asWkb() );
- QgsGeometry* geom1 = copy.geometryAndOwnership();
- QCOMPARE( *geom1->asWkb(), *mGeometry->asWkb() );
- QgsGeometry* geom2 = feature.geometryAndOwnership();
- QCOMPARE( *geom2->asWkb(), *mGeometry->asWkb() );
- Q_NOWARN_DEPRECATED_POP
- delete geom1;
- delete geom2;
}
void TestQgsFeature::asVariant()
@@ -334,13 +303,6 @@ void TestQgsFeature::fields()
QgsFeature copy( original );
QCOMPARE( *copy.fields(), *original.fields() );
- Q_NOWARN_DEPRECATED_PUSH
- //test deprecated setFields( QgsFields* ) method
- QgsFeature feature2;
- feature2.setFields( &mFields );
- QCOMPARE( *feature2.fields(), mFields );
- Q_NOWARN_DEPRECATED_POP
-
//test detach
QgsFields newFields( mFields );
newFields.remove( 2 );
@@ -416,7 +378,7 @@ void TestQgsFeature::attributeUsingField()
void TestQgsFeature::dataStream()
{
QgsFeature originalFeature;
- originalFeature.setGeometry( new QgsGeometry( *mGeometry.data() ) );
+ originalFeature.setGeometry( QgsGeometry( *mGeometry.data() ) );
QByteArray ba;
QDataStream ds( &ba, QIODevice::ReadWrite );
@@ -432,7 +394,7 @@ void TestQgsFeature::dataStream()
QCOMPARE( resultFeature.isValid(), originalFeature.isValid() );
//also test with feature empty geometry
- originalFeature.setGeometry( new QgsGeometry() );
+ originalFeature.setGeometry( QgsGeometry() );
QByteArray ba2;
QDataStream ds2( &ba2, QIODevice::ReadWrite );
ds2 << originalFeature;
@@ -442,21 +404,7 @@ void TestQgsFeature::dataStream()
QCOMPARE( resultFeature.id(), originalFeature.id() );
QCOMPARE( resultFeature.attributes(), originalFeature.attributes() );
- QVERIFY( resultFeature.constGeometry()->isEmpty() );
- QCOMPARE( resultFeature.isValid(), originalFeature.isValid() );
-
- //test with feature with null geometry
- originalFeature.setGeometry( 0 );
- QByteArray ba3;
- QDataStream ds3( &ba3, QIODevice::ReadWrite );
- ds3 << originalFeature;
-
- ds3.device()->seek( 0 );
- ds3 >> resultFeature;
-
- QCOMPARE( resultFeature.id(), originalFeature.id() );
- QCOMPARE( resultFeature.attributes(), originalFeature.attributes() );
- QVERIFY( resultFeature.constGeometry()->isEmpty() );
+ QVERIFY( !resultFeature.constGeometry() );
QCOMPARE( resultFeature.isValid(), originalFeature.isValid() );
}
diff --git a/tests/src/core/testqgslegendrenderer.cpp b/tests/src/core/testqgslegendrenderer.cpp
index 00be5982552..5458957d435 100644
--- a/tests/src/core/testqgslegendrenderer.cpp
+++ b/tests/src/core/testqgslegendrenderer.cpp
@@ -186,13 +186,19 @@ void TestQgsLegendRenderer::init()
QList features;
QgsFeature f1( fields, 1 );
f1.setAttribute( 0, 1 );
- f1.setGeometry( QgsGeometry::fromPoint( QgsPoint( 1.0, 1.0 ) ) );
+ QgsGeometry* f1G = QgsGeometry::fromPoint( QgsPoint( 1.0, 1.0 ) );
+ f1.setGeometry( *f1G );
+ delete f1G;
QgsFeature f2( fields, 2 );
f2.setAttribute( 0, 2 );
- f2.setGeometry( QgsGeometry::fromPoint( QgsPoint( 9.0, 1.0 ) ) );
+ QgsGeometry* f2G = QgsGeometry::fromPoint( QgsPoint( 9.0, 1.0 ) );
+ f2.setGeometry( *f2G );
+ delete f2G;
QgsFeature f3( fields, 3 );
f3.setAttribute( 0, 3 );
- f3.setGeometry( QgsGeometry::fromPoint( QgsPoint( 5.0, 5.0 ) ) );
+ QgsGeometry* f3G = QgsGeometry::fromPoint( QgsPoint( 5.0, 5.0 ) ) ;
+ f3.setGeometry( *f3G );
+ delete f3G;
features << f1 << f2 << f3;
pr->addFeatures( features );
mVL3->updateFields();
@@ -404,13 +410,19 @@ void TestQgsLegendRenderer::testFilterByMapSameSymbol()
QList features;
QgsFeature f1( fields, 1 );
f1.setAttribute( 0, 1 );
- f1.setGeometry( QgsGeometry::fromPoint( QgsPoint( 1.0, 1.0 ) ) );
+ QgsGeometry* f1G = QgsGeometry::fromPoint( QgsPoint( 1.0, 1.0 ) );
+ f1.setGeometry( *f1G );
+ delete f1G;
QgsFeature f2( fields, 2 );
f2.setAttribute( 0, 2 );
- f2.setGeometry( QgsGeometry::fromPoint( QgsPoint( 9.0, 1.0 ) ) );
+ QgsGeometry* f2G = QgsGeometry::fromPoint( QgsPoint( 9.0, 1.0 ) );
+ f2.setGeometry( *f2G );
+ delete f2G;
QgsFeature f3( fields, 3 );
f3.setAttribute( 0, 3 );
- f3.setGeometry( QgsGeometry::fromPoint( QgsPoint( 5.0, 5.0 ) ) );
+ QgsGeometry* f3G = QgsGeometry::fromPoint( QgsPoint( 5.0, 5.0 ) );
+ f3.setGeometry( *f3G );
+ delete f3G;
features << f1 << f2 << f3;
pr->addFeatures( features );
vl4->updateFields();
diff --git a/tests/src/core/testqgsmaprendererjob.cpp b/tests/src/core/testqgsmaprendererjob.cpp
index 39204f8405a..2a1040303c0 100644
--- a/tests/src/core/testqgsmaprendererjob.cpp
+++ b/tests/src/core/testqgsmaprendererjob.cpp
@@ -150,7 +150,8 @@ void TestQgsMapRendererJob::initTestCase()
// delete it in its dtor!
QgsGeometry * mypPolygonGeometry = QgsGeometry::fromPolygon( myPolygon );
QgsFeature myFeature;
- myFeature.setGeometry( mypPolygonGeometry );
+ myFeature.setGeometry( *mypPolygonGeometry );
+ delete mypPolygonGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, i );
//
diff --git a/tests/src/core/testqgsogrutils.cpp b/tests/src/core/testqgsogrutils.cpp
index 51ca659a267..ca17a0d8e2a 100644
--- a/tests/src/core/testqgsogrutils.cpp
+++ b/tests/src/core/testqgsogrutils.cpp
@@ -93,7 +93,7 @@ void TestQgsOgrUtils::cleanup()
void TestQgsOgrUtils::ogrGeometryToQgsGeometry()
{
// test with null geometry
- QVERIFY( !QgsOgrUtils::ogrGeometryToQgsGeometry( nullptr ) );
+ QVERIFY( QgsOgrUtils::ogrGeometryToQgsGeometry( nullptr ).isEmpty() );
// get a geometry from line file, test
OGRDataSourceH hDS = OGROpen( TO8F( mTestFile ), false, nullptr );
@@ -106,10 +106,10 @@ void TestQgsOgrUtils::ogrGeometryToQgsGeometry()
OGRGeometryH ogrGeom = OGR_F_GetGeometryRef( oFeat );
QVERIFY( ogrGeom );
- QScopedPointer< QgsGeometry > geom( QgsOgrUtils::ogrGeometryToQgsGeometry( ogrGeom ) );
- QVERIFY( geom.data() );
- QCOMPARE( geom->geometry()->wkbType(), QgsWKBTypes::LineString );
- QCOMPARE( geom->geometry()->nCoordinates(), 71 );
+ QgsGeometry geom = QgsOgrUtils::ogrGeometryToQgsGeometry( ogrGeom );
+ QVERIFY( !geom.isEmpty() );
+ QCOMPARE( geom.geometry()->wkbType(), QgsWKBTypes::LineString );
+ QCOMPARE( geom.geometry()->nCoordinates(), 71 );
OGR_F_Destroy( oFeat );
OGR_DS_Destroy( hDS );
diff --git a/tests/src/core/testqgspointlocator.cpp b/tests/src/core/testqgspointlocator.cpp
index a945d461d01..e00fb19fc07 100644
--- a/tests/src/core/testqgspointlocator.cpp
+++ b/tests/src/core/testqgspointlocator.cpp
@@ -85,7 +85,9 @@ class TestQgsPointLocator : public QObject
QgsPolyline polyline;
polyline << QgsPoint( 0, 1 ) << QgsPoint( 1, 0 ) << QgsPoint( 1, 1 ) << QgsPoint( 0, 1 );
polygon << polyline;
- ff.setGeometry( QgsGeometry::fromPolygon( polygon ) );
+ QgsGeometry* ffGeom = QgsGeometry::fromPolygon( polygon );
+ ff.setGeometry( *ffGeom );
+ delete ffGeom;
QgsFeatureList flist;
flist << ff;
mVL->dataProvider()->addFeatures( flist );
@@ -202,7 +204,9 @@ class TestQgsPointLocator : public QObject
QgsPolyline polyline;
polyline << QgsPoint( 10, 11 ) << QgsPoint( 11, 10 ) << QgsPoint( 11, 11 ) << QgsPoint( 10, 11 );
polygon << polyline;
- ff.setGeometry( QgsGeometry::fromPolygon( polygon ) );
+ QgsGeometry* ffGeom = QgsGeometry::fromPolygon( polygon ) ;
+ ff.setGeometry( *ffGeom );
+ delete ffGeom;
QgsFeatureList flist;
flist << ff;
bool resA = mVL->addFeature( ff );
@@ -221,7 +225,7 @@ class TestQgsPointLocator : public QObject
// change geometry
QgsGeometry* newGeom = new QgsGeometry( *ff.constGeometry() );
newGeom->moveVertex( 10, 10, 2 ); // change 11,11 to 10,10
- mVL->changeGeometry( ff.id(), newGeom );
+ mVL->changeGeometry( ff.id(), *newGeom );
delete newGeom;
// verify it is changed in the point locator
diff --git a/tests/src/core/testqgssnappingutils.cpp b/tests/src/core/testqgssnappingutils.cpp
index e6237748337..5c61a33f2fd 100644
--- a/tests/src/core/testqgssnappingutils.cpp
+++ b/tests/src/core/testqgssnappingutils.cpp
@@ -67,7 +67,9 @@ class TestQgsSnappingUtils : public QObject
QgsPolyline polyline;
polyline << QgsPoint( 0, 1 ) << QgsPoint( 1, 0 ) << QgsPoint( 1, 1 ) << QgsPoint( 0, 1 );
polygon << polyline;
- ff.setGeometry( QgsGeometry::fromPolygon( polygon ) );
+ QgsGeometry* polygonGeom = QgsGeometry::fromPolygon( polygon );
+ ff.setGeometry( *polygonGeom );
+ delete polygonGeom;
QgsFeatureList flist;
flist << ff;
mVL->dataProvider()->addFeatures( flist );
@@ -182,9 +184,13 @@ class TestQgsSnappingUtils : public QObject
polyline1 << QgsPoint( 0, 0 ) << QgsPoint( 1, 1 );
polyline2 << QgsPoint( 1, 0 ) << QgsPoint( 0, 1 );
QgsFeature f1;
- f1.setGeometry( QgsGeometry::fromPolyline( polyline1 ) );
+ QgsGeometry* f1g = QgsGeometry::fromPolyline( polyline1 ) ;
+ f1.setGeometry( *f1g );
+ delete f1g;
QgsFeature f2;
- f2.setGeometry( QgsGeometry::fromPolyline( polyline2 ) );
+ QgsGeometry* f2g = QgsGeometry::fromPolyline( polyline2 );
+ f2.setGeometry( *f2g );
+ delete f2g;
QgsFeatureList flist;
flist << f1 << f2;
vl->dataProvider()->addFeatures( flist );
diff --git a/tests/src/core/testqgsspatialindex.cpp b/tests/src/core/testqgsspatialindex.cpp
index 4f2a7641d93..901c95d2841 100644
--- a/tests/src/core/testqgsspatialindex.cpp
+++ b/tests/src/core/testqgsspatialindex.cpp
@@ -27,7 +27,9 @@
static QgsFeature _pointFeature( QgsFeatureId id, qreal x, qreal y )
{
QgsFeature f( id );
- f.setGeometry( QgsGeometry::fromPoint( QgsPoint( x, y ) ) );
+ QgsGeometry* g = QgsGeometry::fromPoint( QgsPoint( x, y ) );
+ f.setGeometry( *g );
+ delete g;
return f;
}
@@ -127,7 +129,9 @@ class TestQgsSpatialIndex : public QObject
for ( int k = 0; k < 500; ++k )
{
QgsFeature f( i*1000 + k );
- f.setGeometry( QgsGeometry::fromPoint( QgsPoint( i / 10, i % 10 ) ) );
+ QgsGeometry* g = QgsGeometry::fromPoint( QgsPoint( i / 10, i % 10 ) );
+ f.setGeometry( *g );
+ delete g;
index.insertFeature( f );
}
}
@@ -148,7 +152,9 @@ class TestQgsSpatialIndex : public QObject
for ( int k = 0; k < 500; ++k )
{
QgsFeature f( i*1000 + k );
- f.setGeometry( QgsGeometry::fromPoint( QgsPoint( i / 10, i % 10 ) ) );
+ QgsGeometry* g = QgsGeometry::fromPoint( QgsPoint( i / 10, i % 10 ) );
+ f.setGeometry( *g );
+ delete g;
flist << f;
}
vl->dataProvider()->addFeatures( flist );
diff --git a/tests/src/core/testqgstracer.cpp b/tests/src/core/testqgstracer.cpp
index 01c8c222cf2..a473f7ec86d 100644
--- a/tests/src/core/testqgstracer.cpp
+++ b/tests/src/core/testqgstracer.cpp
@@ -55,7 +55,9 @@ namespace QTest
static QgsFeature make_feature( const QString& wkt )
{
QgsFeature f;
- f.setGeometry( QgsGeometry::fromWkt( wkt ) );
+ QgsGeometry* g = QgsGeometry::fromWkt( wkt ) ;
+ f.setGeometry( *g );
+ delete g;
return f;
}
@@ -252,7 +254,7 @@ void TestQgsTracer::testLayerUpdates()
// make the shortcut again from a different feature
QgsGeometry* g = QgsGeometry::fromWkt( "LINESTRING(10 0, 10 10)" );
- vl->changeGeometry( 2, g ); // change bottom line (second item in wkts)
+ vl->changeGeometry( 2, *g ); // change bottom line (second item in wkts)
delete g;
QgsPolyline points4 = tracer.findShortestPath( QgsPoint( 10, 0 ), QgsPoint( 10, 10 ) );
diff --git a/tests/src/core/testqgsvectorfilewriter.cpp b/tests/src/core/testqgsvectorfilewriter.cpp
index a52521d096a..70234e05001 100644
--- a/tests/src/core/testqgsvectorfilewriter.cpp
+++ b/tests/src/core/testqgsvectorfilewriter.cpp
@@ -149,7 +149,8 @@ void TestQgsVectorFileWriter::createPoint()
// delete it in its dtor!
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( mPoint1 );
QgsFeature myFeature;
- myFeature.setGeometry( mypPointGeometry );
+ myFeature.setGeometry( *mypPointGeometry );
+ delete mypPointGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, "HelloWorld" );
//
@@ -197,7 +198,8 @@ void TestQgsVectorFileWriter::createLine()
// delete it in its dtor!
QgsGeometry * mypLineGeometry = QgsGeometry::fromPolyline( myPolyline );
QgsFeature myFeature;
- myFeature.setGeometry( mypLineGeometry );
+ myFeature.setGeometry( *mypLineGeometry );
+ delete mypLineGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, "HelloWorld" );
//
@@ -250,7 +252,8 @@ void TestQgsVectorFileWriter::createPolygon()
// delete it in its dtor!
QgsGeometry * mypPolygonGeometry = QgsGeometry::fromPolygon( myPolygon );
QgsFeature myFeature;
- myFeature.setGeometry( mypPolygonGeometry );
+ myFeature.setGeometry( *mypPolygonGeometry );
+ delete mypPolygonGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, "HelloWorld" );
//
@@ -310,7 +313,8 @@ void TestQgsVectorFileWriter::polygonGridTest()
// delete it in its dtor!
QgsGeometry * mypPolygonGeometry = QgsGeometry::fromPolygon( myPolygon );
QgsFeature myFeature;
- myFeature.setGeometry( mypPolygonGeometry );
+ myFeature.setGeometry( *mypPolygonGeometry );
+ delete mypPolygonGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, "HelloWorld" );
//
@@ -383,7 +387,8 @@ void TestQgsVectorFileWriter::projectedPlygonGridTest()
// delete it in its dtor!
QgsGeometry * mypPolygonGeometry = QgsGeometry::fromPolygon( myPolygon );
QgsFeature myFeature;
- myFeature.setGeometry( mypPolygonGeometry );
+ myFeature.setGeometry( *mypPolygonGeometry );
+ delete mypPolygonGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, "HelloWorld" );
//
@@ -448,7 +453,8 @@ void TestQgsVectorFileWriter::regression1141()
// delete it in its dtor!
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint );
QgsFeature myFeature;
- myFeature.setGeometry( mypPointGeometry );
+ myFeature.setGeometry( *mypPointGeometry );
+ delete mypPointGeometry;
myFeature.initAttributes( 1 );
myFeature.setAttribute( 0, 10 );
//
diff --git a/tests/src/gui/testqgsrubberband.cpp b/tests/src/gui/testqgsrubberband.cpp
index 927f9ca90c3..7626e856503 100644
--- a/tests/src/gui/testqgsrubberband.cpp
+++ b/tests/src/gui/testqgsrubberband.cpp
@@ -104,8 +104,8 @@ void TestQgsRubberband::testAddSingleMultiGeometries()
mCanvas->setExtent( QgsRectangle( -1e-3, -1e-3, 1e-3, 1e-3 ) ); // otherwise point cannot be converted to canvas coord
- mRubberband->addGeometry( geomSinglePart.data(), mPolygonLayer );
- mRubberband->addGeometry( geomMultiPart.data(), mPolygonLayer );
+ mRubberband->addGeometry( *geomSinglePart.data(), mPolygonLayer );
+ mRubberband->addGeometry( *geomMultiPart.data(), mPolygonLayer );
QVERIFY( mRubberband->numberOfVertices() == 15 );
}
@@ -128,7 +128,7 @@ void TestQgsRubberband::testBoundingRect()
mRubberband = new QgsRubberBand( mCanvas, mPolygonLayer->geometryType() );
mRubberband->setIconSize( 5 ); // default, but better be explicit
mRubberband->setWidth( 1 ); // default, but better be explicit
- mRubberband->addGeometry( geom.data(), mPolygonLayer );
+ mRubberband->addGeometry( *geom.data(), mPolygonLayer );
// 20 pixels for the extent + 3 for pen & icon per side + 2 of padding
QCOMPARE( mRubberband->boundingRect(), QRectF( QPointF( -1, -1 ), QSizeF( 28, 28 ) ) );
@@ -163,19 +163,19 @@ void TestQgsRubberband::testVisibility()
// Check visibility after setting to empty geometry
QSharedPointer emptyGeom( new QgsGeometry );
- mRubberband->setToGeometry( emptyGeom.data(), mPolygonLayer );
+ mRubberband->setToGeometry( *emptyGeom.data(), mPolygonLayer );
QCOMPARE( mRubberband->isVisible(), false );
// Check that visibility changes
mRubberband->setVisible( true );
- mRubberband->setToGeometry( emptyGeom.data(), mPolygonLayer );
+ mRubberband->setToGeometry( *emptyGeom.data(), mPolygonLayer );
QCOMPARE( mRubberband->isVisible(), false );
// Check visibility after setting to valid geometry
QSharedPointer geom( QgsGeometry::fromWkt(
"POLYGON((10 10,10 30,30 30,30 10,10 10))"
) );
- mRubberband->setToGeometry( geom.data(), mPolygonLayer );
+ mRubberband->setToGeometry( *geom.data(), mPolygonLayer );
QCOMPARE( mRubberband->isVisible(), true );
// Add point without update
diff --git a/tests/src/providers/grass/testqgsgrassprovider.cpp b/tests/src/providers/grass/testqgsgrassprovider.cpp
index a8cca70b855..86559104b31 100644
--- a/tests/src/providers/grass/testqgsgrassprovider.cpp
+++ b/tests/src/providers/grass/testqgsgrassprovider.cpp
@@ -930,7 +930,8 @@ QList< TestQgsGrassCommandGroup > TestQgsGrassProvider::createCommands()
grassFeature = TestQgsGrassFeature( GV_POINT );
grassFeature.setFeatureId( 1 );
geometry = new QgsGeometry( new QgsPointV2( QgsWKBTypes::Point, 10, 10, 0 ) );
- grassFeature.setGeometry( geometry );
+ grassFeature.setGeometry( *geometry );
+ delete geometry;
command.grassFeatures << grassFeature;
command.expectedFeature = grassFeature;
commandGroup.commands << command;
@@ -1025,7 +1026,8 @@ QList< TestQgsGrassCommandGroup > TestQgsGrassProvider::createCommands()
line->setPoints( pointList );
pointList.clear();
geometry = new QgsGeometry( line );
- grassFeature.setGeometry( geometry );
+ grassFeature.setGeometry( *geometry );
+ delete geometry;
command.grassFeatures << grassFeature;
command.expectedFeature = grassFeature;
command.attributes["field_int"] = 456;
@@ -1307,7 +1309,7 @@ void TestQgsGrassProvider::edit()
{
fid = commandGroup.fids.value( fid );
}
- if ( !grassLayer->changeGeometry( fid, command.geometry ) )
+ if ( !grassLayer->changeGeometry( fid, *command.geometry ) )
{
reportRow( "cannot change feature geometry" );
commandOk = false;
@@ -1317,7 +1319,7 @@ void TestQgsGrassProvider::edit()
{
expectedFid = commandGroup.expectedFids.value( expectedFid );
}
- if ( !expectedLayer->changeGeometry( expectedFid, command.geometry ) )
+ if ( !expectedLayer->changeGeometry( expectedFid, *command.geometry ) )
{
reportRow( "cannot change expected feature geometry" );
commandOk = false;