Skip to content

Commit

Permalink
Cache default value in editorwidget
Browse files Browse the repository at this point in the history
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 2, 2016
1 parent 97c4bd7 commit 1df5664
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetwrapper.h
Expand Up @@ -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
Expand Down

0 comments on commit 1df5664

Please sign in to comment.