Skip to content

Commit

Permalink
Split tool: prefer default values for new features vs. values copied …
Browse files Browse the repository at this point in the history
…from original feature. Fixes ticket #5475
  • Loading branch information
mhugent committed May 22, 2012
1 parent 5ff3354 commit 5745fb9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -2403,7 +2403,23 @@ int QgsVectorLayer::splitFeatures( const QList<QgsPoint>& splitLine, bool topolo
newGeometry = newGeometries.at( i );
QgsFeature newFeature;
newFeature.setGeometry( newGeometry );
newFeature.setAttributeMap( select_it->attributeMap() );

//use default value where possible (primary key issue), otherwise the value from the original (splitted) feature
QgsAttributeMap newAttributes = select_it->attributeMap();
QVariant defaultValue;
for ( int j = 0; j < newAttributes.size(); ++j )
{
if ( mDataProvider )
{
defaultValue = mDataProvider->defaultValue( j );
if ( !defaultValue.isNull() )
{
newAttributes.insert( j, defaultValue );
}
}
}

newFeature.setAttributeMap( newAttributes );
newFeatures.append( newFeature );
}

Expand Down

0 comments on commit 5745fb9

Please sign in to comment.