QgsGeometry::OperationResult QgsVectorLayerEditUtils::addPart( QgsCurve *ring, QgsFeatureId featureId ) { if ( !mLayer->isSpatial() ) return QgsGeometry::AddPartSelectedGeometryNotFound; QgsGeometry geometry; bool firstPart = false; QgsFeature f; if ( !mLayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) ) return QgsGeometry::AddPartSelectedGeometryNotFound; if ( !f.hasGeometry() ) { //no existing geometry, so adding first part to null geometry firstPart = true; } else { geometry = f.geometry(); } QgsGeometry::OperationResult errorCode = geometry.addPart( ring, mLayer->geometryType() ); if ( errorCode == QgsGeometry::Success ) { if ( firstPart && QgsWkbTypes::isSingleType( mLayer->wkbType() ) && mLayer->dataProvider()->doesStrictFeatureTypeCheck() ) { //convert back to single part if required by layer geometry.convertToSingleType(); } mLayer->editBuffer()->changeGeometry( featureId, geometry ); } return errorCode; }
int QgsVectorLayerEditUtils::addPart( QgsCurveV2* ring, QgsFeatureId featureId ) { if ( !L->hasGeometryType() ) return 6; QgsGeometry geometry; bool firstPart = false; if ( !cache()->geometry( featureId, geometry ) ) // maybe it's in cache { // it's not in cache: let's fetch it from layer QgsFeature f; if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) ) return 6; //not found if ( !f.constGeometry() || f.constGeometry()->isEmpty() ) { //no existing geometry, so adding first part to null geometry firstPart = true; } else { geometry = *f.geometry(); } } int errorCode = geometry.addPart( ring, L->geometryType() ); if ( errorCode == 0 ) { if ( firstPart && QgsWKBTypes::isSingleType( QGis::fromOldWkbType( L->wkbType() ) ) && L->dataProvider()->doesStrictFeatureTypeCheck() ) { //convert back to single part if required by layer geometry.convertToSingleType(); } L->editBuffer()->changeGeometry( featureId, &geometry ); } return errorCode; }