Skip to content
Permalink
Browse files

Avoid recursion in apply on update default values

  • Loading branch information
m-kuhn committed Sep 29, 2017
1 parent cf77ffe commit 2fbb6f09cce747a68c04ffb09cc42b2ed2c2f0e2
Showing with 22 additions and 18 deletions.
  1. +8 −5 python/core/qgsvectorlayer.sip
  2. +1 −3 src/app/qgsattributetypedialog.h
  3. +3 −4 src/core/qgsvectorlayer.cpp
  4. +10 −6 src/core/qgsvectorlayer.h
@@ -925,13 +925,16 @@ Return the provider type for this layer
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = 0 );


bool updateFeature( const QgsFeature &f );
bool updateFeature( const QgsFeature &feature, bool skipDefaultValues = false );
%Docstring
Updates an existing feature. This method needs to query the datasource
on every call. Consider using changeAttributeValue() or
changeGeometry() instead.
\param f Feature to update
:return: True in case of success and False in case of error
on every call. Consider using changeAttributeValue() or
changeGeometry() instead. The id of the feature will be used to match
an existing feature.

\param feature Feature with changed geometry or attributes.
\param skipDefaultValues Default values will not be updated if this is true. False by default.
:return: True in case of success and False in case of error
:rtype: bool
%End

@@ -164,12 +164,10 @@ class APP_EXPORT QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttribut
*/
void setDefaultValueExpression( const QString &expression );



QgsExpressionContext createExpressionContext() const override;

bool applyDefaultValueOnUpdate() const;
void setApplyDefaultValueOnUpdate(bool applyDefaultValueOnUpdate);
void setApplyDefaultValueOnUpdate( bool applyDefaultValueOnUpdate );

private slots:

@@ -780,8 +780,7 @@ void QgsVectorLayer::updateDefaultValues( QgsFeatureId fid, QgsFeature feature )
continue;

feature.setAttribute( idx, defaultValue( idx, feature ) );
// TODO catch recursion!!
updateFeature( feature );
updateFeature( feature, true );
}
}
}
@@ -961,7 +960,7 @@ bool QgsVectorLayer::addFeature( QgsFeature &feature, Flags )
return success;
}

bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature )
bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature, bool skipDefaultValues )
{
bool hasChanged = false;
bool hasError = false;
@@ -1003,7 +1002,7 @@ bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature )
}
}

if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() )
if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() && !skipDefaultValues )
updateDefaultValues( updatedFeature.id(), updatedFeature );

return !hasError;
@@ -907,13 +907,17 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

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

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

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

0 comments on commit 2fbb6f0

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