Skip to content

Commit 099a40b

Browse files
committedOct 20, 2015
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
1 parent 1c76b93 commit 099a40b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 )

‎src/app/qgisappinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
263263
void removeDockWidget( QDockWidget * dockwidget ) override;
264264

265265
//! return CAD dock widget
266-
QgsAdvancedDigitizingDockWidget *cadDockWidget();
266+
QgsAdvancedDigitizingDockWidget *cadDockWidget() override;
267267

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

0 commit comments

Comments
 (0)
Please sign in to comment.