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
  • Loading branch information
nyalldawson committed Oct 20, 2015
1 parent 1c76b93 commit 099a40bdf2a59f87e28b9c6664c6b9da6fd927b4
Showing with 36 additions and 3 deletions.
  1. +35 −2 src/app/qgisapp.cpp
  2. +1 −1 src/app/qgisappinterface.h
@@ -6154,15 +6154,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->fields()[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->fields()[i].typeName() ),
QgsMessageBar::WARNING );
}
}
else
{
vl->changeAttributeValue( fid, i, val );
}
}
firstFeature = false;
}

vl->endEditCommand();
@@ -6277,7 +6295,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->fields()[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->fields()[i].typeName() ),
QgsMessageBar::WARNING );
}
attrs[i] = val;
}
newFeature.setAttributes( attrs );

QgsFeatureIds::const_iterator feature_it = featureIdsAfter.constBegin();
for ( ; feature_it != featureIdsAfter.constEnd(); ++feature_it )
@@ -263,7 +263,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
void removeDockWidget( QDockWidget * dockwidget ) override;

//! return CAD dock widget
QgsAdvancedDigitizingDockWidget *cadDockWidget();
QgsAdvancedDigitizingDockWidget *cadDockWidget() override;

/** Show layer properties dialog for layer
* @param l layer to show properties table for

0 comments on commit 099a40b

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