Skip to content
Permalink
Browse files

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
  • Loading branch information
mhugent
mhugent committed Nov 12, 2010
1 parent c6eced8 commit 59234aae3b7fd20ede602633d5481500c5084538
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/app/qgsfieldcalculator.cpp
@@ -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();
@@ -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() )
{
@@ -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();

0 comments on commit 59234aa

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