Skip to content
Permalink
Browse files

Fix default value 'apply on update' setting not correctly restored

Fixes #17712
  • Loading branch information
nyalldawson committed Jan 16, 2018
1 parent 749468a commit fe2292c59a5fb7c65399aaf8903e33dbe9ab41d4
@@ -38,7 +38,7 @@ not set, the default value will only be used when a feature is created.
%End
public:

QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false );
explicit QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false );
%Docstring
Create a new default value with the given ``expression`` and ``applyOnUpdate`` flag.

@@ -242,7 +242,6 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
mAttributeTypeDialog->setConstraintExpressionEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );
mAttributeTypeDialog->setDefaultValueExpression( mLayer->defaultValueDefinition( index ).expression() );
mAttributeTypeDialog->setApplyDefaultValueOnUpdate( mLayer->defaultValueDefinition( index ).applyOnUpdate() );
//confustion (will be removed): das hier funktioniert nicht, es is neu, aber ich weiss nicht woher: mAttributeTypeDialog->setDefaultValueExpression( mLayer->defaultValueExpression( index ) );

mAttributeTypeDialog->setEditorWidgetConfig( cfg.mEditorWidgetConfig );
mAttributeTypeDialog->setEditorWidgetType( cfg.mEditorWidgetType );
@@ -57,7 +57,7 @@ class CORE_EXPORT QgsDefaultValue
* Create a new default value with the given \a expression and \a applyOnUpdate flag.
* \see QgsVectorLayer::setDefaultValueDefinition
*/
QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false );
explicit QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false );
bool operator==( const QgsDefaultValue &other ) const;

/**
@@ -3159,9 +3159,9 @@ void QgsVectorLayer::setDefaultValueDefinition( int index, const QgsDefaultValue
QgsDefaultValue QgsVectorLayer::defaultValueDefinition( int index ) const
{
if ( index < 0 || index >= mFields.count() )
return QString();
return QgsDefaultValue();
else
return mFields.at( index ).defaultValueDefinition().expression();
return mFields.at( index ).defaultValueDefinition();
}

QSet<QVariant> QgsVectorLayer::uniqueValues( int index, int limit ) const
@@ -135,7 +135,7 @@ void TestQgsField::gettersSetters()
QCOMPARE( field.comment(), QString( "comment" ) );
field.setAlias( QStringLiteral( "alias" ) );
QCOMPARE( field.alias(), QString( "alias" ) );
field.setDefaultValueDefinition( QStringLiteral( "1+2" ) );
field.setDefaultValueDefinition( QgsDefaultValue( QStringLiteral( "1+2" ) ) );
QCOMPARE( field.defaultValueDefinition().expression(), QString( "1+2" ) );
QgsFieldConstraints constraints;
constraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, QgsFieldConstraints::ConstraintOriginProvider );
@@ -244,10 +244,10 @@ void TestQgsField::equality()
QVERIFY( !( field1 == field2 ) );
QVERIFY( field1 != field2 );
field2.setAlias( QString() );
field2.setDefaultValueDefinition( QStringLiteral( "1+2" ) );
field2.setDefaultValueDefinition( QgsDefaultValue( QStringLiteral( "1+2" ) ) );
QVERIFY( !( field1 == field2 ) );
QVERIFY( field1 != field2 );
field2.setDefaultValueDefinition( QString() );
field2.setDefaultValueDefinition( QgsDefaultValue() );
constraints = field2.constraints();
constraints.removeConstraint( QgsFieldConstraints::ConstraintNotNull );
field2.setConstraints( constraints );
@@ -461,7 +461,7 @@ void TestQgsField::dataStream()
original.setTypeName( QStringLiteral( "typename1" ) );
original.setComment( QStringLiteral( "comment1" ) );
original.setAlias( QStringLiteral( "alias" ) );
original.setDefaultValueDefinition( QStringLiteral( "default" ) );
original.setDefaultValueDefinition( QgsDefaultValue( QStringLiteral( "default" ) ) );
QgsFieldConstraints constraints;
constraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, QgsFieldConstraints::ConstraintOriginProvider );
constraints.setConstraint( QgsFieldConstraints::ConstraintUnique, QgsFieldConstraints::ConstraintOriginLayer );
@@ -2061,14 +2061,28 @@ def testGetSetDefaults(self):
layer.setDefaultValueDefinition(0, QgsDefaultValue("'test'"))
self.assertTrue(layer.defaultValueDefinition(0))
self.assertEqual(layer.defaultValueDefinition(0).expression(), "'test'")
self.assertFalse(layer.defaultValueDefinition(0).applyOnUpdate())
self.assertFalse(layer.defaultValueDefinition(1))
self.assertFalse(layer.defaultValueDefinition(1).applyOnUpdate())
self.assertFalse(layer.defaultValueDefinition(2))
self.assertFalse(layer.defaultValueDefinition(2).applyOnUpdate())
self.assertEqual(layer.fields().at(0).defaultValueDefinition().expression(), "'test'")

layer.setDefaultValueDefinition(1, QgsDefaultValue("2+2"))
self.assertEqual(layer.defaultValueDefinition(0).expression(), "'test'")
self.assertFalse(layer.defaultValueDefinition(0).applyOnUpdate())
self.assertEqual(layer.defaultValueDefinition(1).expression(), "2+2")
self.assertFalse(layer.defaultValueDefinition(1).applyOnUpdate())
self.assertFalse(layer.defaultValueDefinition(2))
self.assertFalse(layer.defaultValueDefinition(2).applyOnUpdate())
self.assertEqual(layer.fields().at(0).defaultValueDefinition().expression(), "'test'")
self.assertEqual(layer.fields().at(1).defaultValueDefinition().expression(), "2+2")

layer.setDefaultValueDefinition(1, QgsDefaultValue("2+2", True))
self.assertEqual(layer.defaultValueDefinition(0).expression(), "'test'")
self.assertFalse(layer.defaultValueDefinition(0).applyOnUpdate())
self.assertEqual(layer.defaultValueDefinition(1).expression(), "2+2")
self.assertTrue(layer.defaultValueDefinition(1).applyOnUpdate())
self.assertEqual(layer.fields().at(0).defaultValueDefinition().expression(), "'test'")
self.assertEqual(layer.fields().at(1).defaultValueDefinition().expression(), "2+2")

Binary file not shown.

0 comments on commit fe2292c

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