Skip to content

Commit cf77ffe

Browse files
committedSep 29, 2017
Config interface for apply on update default values
1 parent 8928959 commit cf77ffe

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed
 

‎src/app/qgsattributetypedialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ QgsExpressionContext QgsAttributeTypeDialog::createExpressionContext() const
308308
return context;
309309
}
310310

311+
bool QgsAttributeTypeDialog::applyDefaultValueOnUpdate() const
312+
{
313+
return mApplyDefaultValueOnUpdateCheckBox->isChecked();
314+
}
315+
316+
void QgsAttributeTypeDialog::setApplyDefaultValueOnUpdate(bool applyDefaultValueOnUpdate)
317+
{
318+
mApplyDefaultValueOnUpdateCheckBox->setChecked( applyDefaultValueOnUpdate );
319+
}
320+
311321
QString QgsAttributeTypeDialog::constraintExpression() const
312322
{
313323
return constraintExpressionWidget->asExpression();

‎src/app/qgsattributetypedialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ class APP_EXPORT QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttribut
164164
*/
165165
void setDefaultValueExpression( const QString &expression );
166166

167+
168+
167169
QgsExpressionContext createExpressionContext() const override;
168170

171+
bool applyDefaultValueOnUpdate() const;
172+
void setApplyDefaultValueOnUpdate(bool applyDefaultValueOnUpdate);
173+
169174
private slots:
170175

171176
/**

‎src/app/qgsfieldsproperties.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ void QgsFieldsProperties::attributeTypeDialog()
575575
attributeTypeDialog.setConstraintExpressionDescription( cfg.mConstraintDescription );
576576
attributeTypeDialog.setConstraintExpressionEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );
577577
attributeTypeDialog.setDefaultValueExpression( mLayer->defaultValueDefinition( index ).expression() );
578+
attributeTypeDialog.setApplyDefaultValueOnUpdate( mLayer->defaultValueDefinition( index ).applyOnUpdate() );
578579

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

602603
cfg.mConstraintDescription = attributeTypeDialog.constraintExpressionDescription();
603604
cfg.mConstraint = attributeTypeDialog.constraintExpression();
604-
mLayer->setDefaultValueDefinition( index, attributeTypeDialog.defaultValueExpression() );
605+
mLayer->setDefaultValueDefinition( index, QgsDefaultValue( attributeTypeDialog.defaultValueExpression(), attributeTypeDialog.applyDefaultValueOnUpdate() ) );
605606

606607
cfg.mEditorWidgetType = attributeTypeDialog.editorWidgetType();
607608
cfg.mEditorWidgetConfig = attributeTypeDialog.editorWidgetConfig();

‎src/ui/qgsattributetypeedit.ui

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
</property>
140140
</widget>
141141
</item>
142-
<item row="2" column="0">
143-
<widget class="QLabel" name="label_4">
142+
<item row="3" column="1">
143+
<widget class="QLabel" name="mDefaultPreviewLabel">
144144
<property name="text">
145-
<string>Preview</string>
145+
<string/>
146146
</property>
147147
</widget>
148148
</item>
@@ -153,10 +153,20 @@
153153
</property>
154154
</widget>
155155
</item>
156-
<item row="2" column="1">
157-
<widget class="QLabel" name="mDefaultPreviewLabel">
156+
<item row="3" column="0">
157+
<widget class="QLabel" name="label_4">
158158
<property name="text">
159-
<string/>
159+
<string>Preview</string>
160+
</property>
161+
</widget>
162+
</item>
163+
<item row="4" column="0" colspan="2">
164+
<widget class="QCheckBox" name="mApplyDefaultValueOnUpdateCheckBox">
165+
<property name="toolTip">
166+
<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>
167+
</property>
168+
<property name="text">
169+
<string>Apply default value on update</string>
160170
</property>
161171
</widget>
162172
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.