mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Continue field calculation upon error only for division through zero
git-svn-id: http://svn.osgeo.org/qgis/trunk@14557 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
71725ce3d4
commit
8f30520f2c
@ -143,6 +143,7 @@ void QgsFieldCalculator::accept()
|
|||||||
|
|
||||||
//go through all the features and change the new attribute
|
//go through all the features and change the new attribute
|
||||||
QgsFeature feature;
|
QgsFeature feature;
|
||||||
|
bool calculationSuccess = true;
|
||||||
|
|
||||||
bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
|
bool onlySelected = ( mOnlyUpdateSelectedCheckBox->checkState() == Qt::Checked );
|
||||||
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();
|
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();
|
||||||
@ -171,7 +172,15 @@ void QgsFieldCalculator::accept()
|
|||||||
if ( value.isError() )
|
if ( value.isError() )
|
||||||
{
|
{
|
||||||
//insert NULL value for this feature and continue the calculation
|
//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() )
|
else if ( value.isNumeric() )
|
||||||
{
|
{
|
||||||
@ -188,6 +197,14 @@ void QgsFieldCalculator::accept()
|
|||||||
// stop blocking layerModified signals and make sure that one layerModified signal is emitted
|
// stop blocking layerModified signals and make sure that one layerModified signal is emitted
|
||||||
mVectorLayer->blockSignals( false );
|
mVectorLayer->blockSignals( false );
|
||||||
mVectorLayer->setModified( true, 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();
|
mVectorLayer->endEditCommand();
|
||||||
}
|
}
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user