@@ -6154,15 +6154,33 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
61546154 QgsAttributes merged = d.mergedAttributes ();
61556155 QSet<int > toSkip = d.skippedAttributeIndexes ();
61566156
6157+ bool firstFeature = true ;
61576158 Q_FOREACH ( QgsFeatureId fid, vl->selectedFeaturesIds () )
61586159 {
61596160 for ( int i = 0 ; i < merged.count (); ++i )
61606161 {
61616162 if ( toSkip.contains ( i ) )
61626163 continue ;
61636164
6164- vl->changeAttributeValue ( fid, i, merged.at ( i ) );
6165+ QVariant val = merged.at ( i );
6166+ // convert to destination data type
6167+ if ( ! vl->fields ()[i].convertCompatible ( val ) )
6168+ {
6169+ if ( firstFeature )
6170+ {
6171+ // only warn on first feature
6172+ messageBar ()->pushMessage (
6173+ tr ( " Invalid result" ),
6174+ tr ( " Could not store value '%1' in field of type %2" ).arg ( merged.at ( i ).toString (), vl->fields ()[i].typeName () ),
6175+ QgsMessageBar::WARNING );
6176+ }
6177+ }
6178+ else
6179+ {
6180+ vl->changeAttributeValue ( fid, i, val );
6181+ }
61656182 }
6183+ firstFeature = false ;
61666184 }
61676185
61686186 vl->endEditCommand ();
@@ -6277,7 +6295,22 @@ void QgisApp::mergeSelectedFeatures()
62776295 // create new feature
62786296 QgsFeature newFeature;
62796297 newFeature.setGeometry ( unionGeom );
6280- newFeature.setAttributes ( d.mergedAttributes () );
6298+
6299+ QgsAttributes attrs = d.mergedAttributes ();
6300+ for ( int i = 0 ; i < attrs.count (); ++i )
6301+ {
6302+ QVariant val = attrs.at ( i );
6303+ // convert to destination data type
6304+ if ( ! vl->fields ()[i].convertCompatible ( val ) )
6305+ {
6306+ messageBar ()->pushMessage (
6307+ tr ( " Invalid result" ),
6308+ tr ( " Could not store value '%1' in field of type %2" ).arg ( attrs.at ( i ).toString (), vl->fields ()[i].typeName () ),
6309+ QgsMessageBar::WARNING );
6310+ }
6311+ attrs[i] = val;
6312+ }
6313+ newFeature.setAttributes ( attrs );
62816314
62826315 QgsFeatureIds::const_iterator feature_it = featureIdsAfter.constBegin ();
62836316 for ( ; feature_it != featureIdsAfter.constEnd (); ++feature_it )
0 commit comments