Skip to content

Commit 2fbb6f0

Browse files
committedSep 29, 2017
Avoid recursion in apply on update default values
1 parent cf77ffe commit 2fbb6f0

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed
 

‎python/core/qgsvectorlayer.sip

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,16 @@ Return the provider type for this layer
925925
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = 0 );
926926

927927

928-
bool updateFeature( const QgsFeature &f );
928+
bool updateFeature( const QgsFeature &feature, bool skipDefaultValues = false );
929929
%Docstring
930930
Updates an existing feature. This method needs to query the datasource
931-
on every call. Consider using changeAttributeValue() or
932-
changeGeometry() instead.
933-
\param f Feature to update
934-
:return: True in case of success and False in case of error
931+
on every call. Consider using changeAttributeValue() or
932+
changeGeometry() instead. The id of the feature will be used to match
933+
an existing feature.
934+
935+
\param feature Feature with changed geometry or attributes.
936+
\param skipDefaultValues Default values will not be updated if this is true. False by default.
937+
:return: True in case of success and False in case of error
935938
:rtype: bool
936939
%End
937940

‎src/app/qgsattributetypedialog.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,10 @@ class APP_EXPORT QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttribut
164164
*/
165165
void setDefaultValueExpression( const QString &expression );
166166

167-
168-
169167
QgsExpressionContext createExpressionContext() const override;
170168

171169
bool applyDefaultValueOnUpdate() const;
172-
void setApplyDefaultValueOnUpdate(bool applyDefaultValueOnUpdate);
170+
void setApplyDefaultValueOnUpdate( bool applyDefaultValueOnUpdate );
173171

174172
private slots:
175173

‎src/core/qgsvectorlayer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,7 @@ void QgsVectorLayer::updateDefaultValues( QgsFeatureId fid, QgsFeature feature )
780780
continue;
781781

782782
feature.setAttribute( idx, defaultValue( idx, feature ) );
783-
// TODO catch recursion!!
784-
updateFeature( feature );
783+
updateFeature( feature, true );
785784
}
786785
}
787786
}
@@ -961,7 +960,7 @@ bool QgsVectorLayer::addFeature( QgsFeature &feature, Flags )
961960
return success;
962961
}
963962

964-
bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature )
963+
bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature, bool skipDefaultValues )
965964
{
966965
bool hasChanged = false;
967966
bool hasError = false;
@@ -1003,7 +1002,7 @@ bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature )
10031002
}
10041003
}
10051004

1006-
if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() )
1005+
if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() && !skipDefaultValues )
10071006
updateDefaultValues( updatedFeature.id(), updatedFeature );
10081007

10091008
return !hasError;

‎src/core/qgsvectorlayer.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,17 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
907907

908908
bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = 0 ) override;
909909

910-
/** Updates an existing feature. This method needs to query the datasource
911-
on every call. Consider using changeAttributeValue() or
912-
changeGeometry() instead.
913-
\param f Feature to update
914-
\returns True in case of success and False in case of error
910+
/**
911+
* Updates an existing feature. This method needs to query the datasource
912+
* on every call. Consider using changeAttributeValue() or
913+
* changeGeometry() instead. The id of the feature will be used to match
914+
* an existing feature.
915+
*
916+
* \param feature Feature with changed geometry or attributes.
917+
* \param skipDefaultValues Default values will not be updated if this is true. False by default.
918+
* \returns True in case of success and False in case of error
915919
*/
916-
bool updateFeature( const QgsFeature &f );
920+
bool updateFeature( const QgsFeature &feature, bool skipDefaultValues = false );
917921

918922
/** Insert a new vertex before the given vertex number,
919923
* in the given ring, item (first number is index 0), and feature

0 commit comments

Comments
 (0)
Please sign in to comment.