Skip to content

Commit 59234aa

Browse files
author
mhugent
committed
Continue field calculation upon error only for division through zero
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14557 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c6eced8 commit 59234aa

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/app/qgsfieldcalculator.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void QgsFieldCalculator::accept()
143143

144144
//go through all the features and change the new attribute
145145
QgsFeature feature;
146+
bool calculationSuccess = true;
146147

147148
bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
148149
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();
@@ -171,7 +172,15 @@ void QgsFieldCalculator::accept()
171172
if ( value.isError() )
172173
{
173174
//insert NULL value for this feature and continue the calculation
174-
mVectorLayer->changeAttributeValue( feature.id(), attributeId, QVariant(), false );
175+
if( searchTree->errorMsg() == QObject::tr( "Division by zero." ) )
176+
{
177+
mVectorLayer->changeAttributeValue( feature.id(), attributeId, QVariant(), false );
178+
}
179+
else
180+
{
181+
calculationSuccess = false;
182+
break;
183+
}
175184
}
176185
else if ( value.isNumeric() )
177186
{
@@ -188,6 +197,14 @@ void QgsFieldCalculator::accept()
188197
// stop blocking layerModified signals and make sure that one layerModified signal is emitted
189198
mVectorLayer->blockSignals( false );
190199
mVectorLayer->setModified( true, false );
200+
201+
if ( !calculationSuccess )
202+
{
203+
QMessageBox::critical( 0, tr( "Error" ), tr( "An error occured while evaluating the calculation string." ) );
204+
mVectorLayer->destroyEditCommand();
205+
return;
206+
}
207+
191208
mVectorLayer->endEditCommand();
192209
}
193210
QDialog::accept();

0 commit comments

Comments
 (0)