@@ -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