Skip to content

Commit

Permalink
Config interface for apply on update default values
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 29, 2017
1 parent 8928959 commit cf77ffe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ QgsExpressionContext QgsAttributeTypeDialog::createExpressionContext() const
return context;
}

bool QgsAttributeTypeDialog::applyDefaultValueOnUpdate() const
{
return mApplyDefaultValueOnUpdateCheckBox->isChecked();
}

void QgsAttributeTypeDialog::setApplyDefaultValueOnUpdate(bool applyDefaultValueOnUpdate)
{
mApplyDefaultValueOnUpdateCheckBox->setChecked( applyDefaultValueOnUpdate );
}

QString QgsAttributeTypeDialog::constraintExpression() const
{
return constraintExpressionWidget->asExpression();
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsattributetypedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ 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);

private slots:

/**
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ void QgsFieldsProperties::attributeTypeDialog()
attributeTypeDialog.setConstraintExpressionDescription( cfg.mConstraintDescription );
attributeTypeDialog.setConstraintExpressionEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );
attributeTypeDialog.setDefaultValueExpression( mLayer->defaultValueDefinition( index ).expression() );
attributeTypeDialog.setApplyDefaultValueOnUpdate( mLayer->defaultValueDefinition( index ).applyOnUpdate() );

attributeTypeDialog.setEditorWidgetConfig( cfg.mEditorWidgetConfig );
attributeTypeDialog.setEditorWidgetType( cfg.mEditorWidgetType );
Expand All @@ -601,7 +602,7 @@ void QgsFieldsProperties::attributeTypeDialog()

cfg.mConstraintDescription = attributeTypeDialog.constraintExpressionDescription();
cfg.mConstraint = attributeTypeDialog.constraintExpression();
mLayer->setDefaultValueDefinition( index, attributeTypeDialog.defaultValueExpression() );
mLayer->setDefaultValueDefinition( index, QgsDefaultValue( attributeTypeDialog.defaultValueExpression(), attributeTypeDialog.applyDefaultValueOnUpdate() ) );

cfg.mEditorWidgetType = attributeTypeDialog.editorWidgetType();
cfg.mEditorWidgetConfig = attributeTypeDialog.editorWidgetConfig();
Expand Down
22 changes: 16 additions & 6 deletions src/ui/qgsattributetypeedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<item row="3" column="1">
<widget class="QLabel" name="mDefaultPreviewLabel">
<property name="text">
<string>Preview</string>
<string/>
</property>
</widget>
</item>
Expand All @@ -153,10 +153,20 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="mDefaultPreviewLabel">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
<string>Preview</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mApplyDefaultValueOnUpdateCheckBox">
<property name="toolTip">
<string>&lt;p&gt;With this option checked, the default value will not only be used when the feature is first created, but also whenever a feature's attribute or geometry is changed.&lt;/p&gt;&lt;p&gt;This is often useful for a last_modified timestamp or to record the username that last modified the feature.&lt;/p&gt;</string>
</property>
<property name="text">
<string>Apply default value on update</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit cf77ffe

Please sign in to comment.