Skip to content
Permalink
Browse files

Cache default value in editorwidget

Makes sure that repeated calls return the same value for a given editor widget.
This avoids unstable behavior and unrequired updates of serial numbers.
  • Loading branch information
m-kuhn committed Jun 1, 2016
1 parent 97c4bd7 commit 1df5664d84b4cb254e49a81819bfdd32d5e096f7
@@ -42,7 +42,9 @@ QgsField QgsEditorWidgetWrapper::field() const

QVariant QgsEditorWidgetWrapper::defaultValue() const
{
return layer()->dataProvider()->defaultValue( mFieldIdx );
mDefaultValue = layer()->dataProvider()->defaultValue( mFieldIdx );

return mDefaultValue;
}

QgsEditorWidgetWrapper* QgsEditorWidgetWrapper::fromWidget( QWidget* widget )
@@ -224,14 +224,15 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
virtual void updateConstraintWidgetStatus();

private:
/**
* Boolean storing the current validity of the constraint for this widget.
*/
bool mValidConstraint;

private:
int mFieldIdx;
QgsFeature mFeature;
mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
};

// We'll use this class inside a QVariant in the widgets properties

0 comments on commit 1df5664

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