Skip to content

Commit

Permalink
Continue field calculation upon error only for division through zero
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14557 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 12, 2010
1 parent c6eced8 commit 59234aa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/qgsfieldcalculator.cpp
Expand Up @@ -143,6 +143,7 @@ void QgsFieldCalculator::accept()

//go through all the features and change the new attribute
QgsFeature feature;
bool calculationSuccess = true;

bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();
Expand Down Expand Up @@ -171,7 +172,15 @@ void QgsFieldCalculator::accept()
if ( value.isError() )
{
//insert NULL value for this feature and continue the calculation
mVectorLayer->changeAttributeValue( feature.id(), attributeId, QVariant(), false );
if( searchTree->errorMsg() == QObject::tr( "Division by zero." ) )
{
mVectorLayer->changeAttributeValue( feature.id(), attributeId, QVariant(), false );
}
else
{
calculationSuccess = false;
break;
}
}
else if ( value.isNumeric() )
{
Expand All @@ -188,6 +197,14 @@ void QgsFieldCalculator::accept()
// stop blocking layerModified signals and make sure that one layerModified signal is emitted
mVectorLayer->blockSignals( false );
mVectorLayer->setModified( true, false );

if ( !calculationSuccess )
{
QMessageBox::critical( 0, tr( "Error" ), tr( "An error occured while evaluating the calculation string." ) );
mVectorLayer->destroyEditCommand();
return;
}

mVectorLayer->endEditCommand();
}
QDialog::accept();
Expand Down

0 comments on commit 59234aa

Please sign in to comment.