Skip to content
Permalink
Browse files

Fix merge attributes/features tool resets values to null for int fields

Also add a warning if merged attribute value is not compatible with
field type.

Fix #12842

(cherry-picked from 099a40b)
  • Loading branch information
nyalldawson committed Nov 19, 2015
1 parent 45d80f9 commit c5762816750f05da6033f04c6aebf3f0925a45f7
Showing with 35 additions and 2 deletions.
  1. +35 −2 src/app/qgisapp.cpp
@@ -5891,15 +5891,33 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
QgsAttributes merged = d.mergedAttributes();
QSet<int> toSkip = d.skippedAttributeIndexes();

bool firstFeature = true;
Q_FOREACH ( QgsFeatureId fid, vl->selectedFeaturesIds() )
{
for ( int i = 0; i < merged.count(); ++i )
{
if ( toSkip.contains( i ) )
continue;

vl->changeAttributeValue( fid, i, merged.at( i ) );
QVariant val = merged.at( i );
// convert to destination data type
if ( ! vl->pendingFields()[i].convertCompatible( val ) )
{
if ( firstFeature )
{
//only warn on first feature
messageBar()->pushMessage(
tr( "Invalid result" ),
tr( "Could not store value '%1' in field of type %2" ).arg( merged.at( i ).toString(), vl->pendingFields()[i].typeName() ),
QgsMessageBar::WARNING );
}
}
else
{
vl->changeAttributeValue( fid, i, val );
}
}
firstFeature = false;
}

vl->endEditCommand();
@@ -6014,7 +6032,22 @@ void QgisApp::mergeSelectedFeatures()
//create new feature
QgsFeature newFeature;
newFeature.setGeometry( unionGeom );
newFeature.setAttributes( d.mergedAttributes() );

QgsAttributes attrs = d.mergedAttributes();
for ( int i = 0; i < attrs.count(); ++i )
{
QVariant val = attrs.at( i );
// convert to destination data type
if ( ! vl->pendingFields()[i].convertCompatible( val ) )
{
messageBar()->pushMessage(
tr( "Invalid result" ),
tr( "Could not store value '%1' in field of type %2" ).arg( attrs.at( i ).toString(), vl->pendingFields()[i].typeName() ),
QgsMessageBar::WARNING );
}
attrs[i] = val;
}
newFeature.setAttributes( attrs );

QgsFeatureIds::const_iterator feature_it = featureIdsAfter.constBegin();
for ( ; feature_it != featureIdsAfter.constEnd(); ++feature_it )

0 comments on commit c576281

Please sign in to comment.
You can’t perform that action at this time.