@@ -5891,15 +5891,33 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
5891
5891
QgsAttributes merged = d.mergedAttributes ();
5892
5892
QSet<int > toSkip = d.skippedAttributeIndexes ();
5893
5893
5894
+ bool firstFeature = true ;
5894
5895
Q_FOREACH ( QgsFeatureId fid, vl->selectedFeaturesIds () )
5895
5896
{
5896
5897
for ( int i = 0 ; i < merged.count (); ++i )
5897
5898
{
5898
5899
if ( toSkip.contains ( i ) )
5899
5900
continue ;
5900
5901
5901
- vl->changeAttributeValue ( fid, i, merged.at ( i ) );
5902
+ QVariant val = merged.at ( i );
5903
+ // convert to destination data type
5904
+ if ( ! vl->pendingFields ()[i].convertCompatible ( val ) )
5905
+ {
5906
+ if ( firstFeature )
5907
+ {
5908
+ // only warn on first feature
5909
+ messageBar ()->pushMessage (
5910
+ tr ( " Invalid result" ),
5911
+ tr ( " Could not store value '%1' in field of type %2" ).arg ( merged.at ( i ).toString (), vl->pendingFields ()[i].typeName () ),
5912
+ QgsMessageBar::WARNING );
5913
+ }
5914
+ }
5915
+ else
5916
+ {
5917
+ vl->changeAttributeValue ( fid, i, val );
5918
+ }
5902
5919
}
5920
+ firstFeature = false ;
5903
5921
}
5904
5922
5905
5923
vl->endEditCommand ();
@@ -6014,7 +6032,22 @@ void QgisApp::mergeSelectedFeatures()
6014
6032
// create new feature
6015
6033
QgsFeature newFeature;
6016
6034
newFeature.setGeometry ( unionGeom );
6017
- newFeature.setAttributes ( d.mergedAttributes () );
6035
+
6036
+ QgsAttributes attrs = d.mergedAttributes ();
6037
+ for ( int i = 0 ; i < attrs.count (); ++i )
6038
+ {
6039
+ QVariant val = attrs.at ( i );
6040
+ // convert to destination data type
6041
+ if ( ! vl->pendingFields ()[i].convertCompatible ( val ) )
6042
+ {
6043
+ messageBar ()->pushMessage (
6044
+ tr ( " Invalid result" ),
6045
+ tr ( " Could not store value '%1' in field of type %2" ).arg ( attrs.at ( i ).toString (), vl->pendingFields ()[i].typeName () ),
6046
+ QgsMessageBar::WARNING );
6047
+ }
6048
+ attrs[i] = val;
6049
+ }
6050
+ newFeature.setAttributes ( attrs );
6018
6051
6019
6052
QgsFeatureIds::const_iterator feature_it = featureIdsAfter.constBegin ();
6020
6053
for ( ; feature_it != featureIdsAfter.constEnd (); ++feature_it )
0 commit comments