Skip to content

Commit

Permalink
Rename QgsField::defaultValue
Browse files Browse the repository at this point in the history
It's now called QgsField::defaultValueDefinition, because it's only a
value after being evaluated
  • Loading branch information
m-kuhn committed Sep 29, 2017
1 parent 650b64e commit f0b7149
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions python/core/qgsfield.sip
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,23 @@ Gets variant type of the field as it will be retrieved from data source
Set the field comment
%End

QgsDefaultValue defaultValue() const;
QgsDefaultValue defaultValueDefinition() const;
%Docstring
Returns the expression used when calculating the default value for the field.
:return: expression evaluated when calculating default values for field, or an
empty string if no default is set
.. versionadded:: 3.0
.. seealso:: setDefaultValueExpression()
.. seealso:: setDefaultValueDefinition()
:rtype: QgsDefaultValue
%End

void setDefaultValue( const QgsDefaultValue &defaultValue );
void setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition );
%Docstring
Sets an expression to use when calculating the default value for the field.
\param expression expression to evaluate when calculating default values for field. Pass
an empty expression to clear the default.
.. versionadded:: 3.0
.. seealso:: defaultValueExpression()
.. seealso:: defaultValueDefinition()
%End

const QgsFieldConstraints &constraints() const;
Expand Down
14 changes: 7 additions & 7 deletions src/core/qgsfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ void QgsField::setComment( const QString &comment )
d->comment = comment;
}

QgsDefaultValue QgsField::defaultValue() const
QgsDefaultValue QgsField::defaultValueDefinition() const
{
return d->defaultValue;
return d->defaultValueDefinition;
}

void QgsField::setDefaultValue( const QgsDefaultValue &defaultValue )
void QgsField::setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition )
{
d->defaultValue = defaultValue;
d->defaultValueDefinition = defaultValueDefinition;
}

void QgsField::setConstraints( const QgsFieldConstraints &constraints )
Expand Down Expand Up @@ -307,8 +307,8 @@ QDataStream &operator<<( QDataStream &out, const QgsField &field )
out << field.precision();
out << field.comment();
out << field.alias();
out << field.defaultValue().expression();
out << field.defaultValue().applyOnUpdate();
out << field.defaultValueDefinition().expression();
out << field.defaultValueDefinition().applyOnUpdate();
out << field.constraints().constraints();
out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
Expand Down Expand Up @@ -336,7 +336,7 @@ QDataStream &operator>>( QDataStream &in, QgsField &field )
field.setPrecision( static_cast< int >( precision ) );
field.setComment( comment );
field.setAlias( alias );
field.setDefaultValue( defaultValueExpression );
field.setDefaultValueDefinition( defaultValueExpression );
QgsFieldConstraints fieldConstraints;
if ( constraints & QgsFieldConstraints::ConstraintNotNull )
{
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CORE_EXPORT QgsField
Q_PROPERTY( QString comment READ comment WRITE setComment )
Q_PROPERTY( QString name READ name WRITE setName )
Q_PROPERTY( QString alias READ alias WRITE setAlias )
Q_PROPERTY( QgsDefaultValue defaultValue READ defaultValue WRITE setDefaultValue )
Q_PROPERTY( QgsDefaultValue defaultValueDefinition READ defaultValueDefinition WRITE setDefaultValueDefinition )
Q_PROPERTY( QgsFieldConstraints constraints READ constraints WRITE setConstraints )

public:
Expand Down Expand Up @@ -198,17 +198,17 @@ class CORE_EXPORT QgsField
* \returns expression evaluated when calculating default values for field, or an
* empty string if no default is set
* \since QGIS 3.0
* \see setDefaultValueExpression()
* \see setDefaultValueDefinition()
*/
QgsDefaultValue defaultValue() const;
QgsDefaultValue defaultValueDefinition() const;

/** Sets an expression to use when calculating the default value for the field.
* \param expression expression to evaluate when calculating default values for field. Pass
* an empty expression to clear the default.
* \since QGIS 3.0
* \see defaultValueExpression()
* \see defaultValueDefinition()
*/
void setDefaultValue( const QgsDefaultValue &defaultValue );
void setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition );

/**
* Returns constraints which are present for the field.
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsfield_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class QgsFieldPrivate : public QSharedData
, precision( other.precision )
, comment( other.comment )
, alias( other.alias )
, defaultValue( other.defaultValue )
, defaultValueDefinition( other.defaultValueDefinition )
, constraints( other.constraints )
{
}
Expand All @@ -84,7 +84,7 @@ class QgsFieldPrivate : public QSharedData
{
return ( ( name == other.name ) && ( type == other.type ) && ( subType == other.subType )
&& ( length == other.length ) && ( precision == other.precision )
&& ( alias == other.alias ) && ( defaultValue == other.defaultValue )
&& ( alias == other.alias ) && ( defaultValueDefinition == other.defaultValueDefinition )
&& ( constraints == other.constraints ) );
}

Expand Down Expand Up @@ -113,7 +113,7 @@ class QgsFieldPrivate : public QSharedData
QString alias;

//! Default value
QgsDefaultValue defaultValue;
QgsDefaultValue defaultValueDefinition;

//! Field constraints
QgsFieldConstraints constraints;
Expand Down
15 changes: 8 additions & 7 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,8 +2099,8 @@ bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString
{
QDomElement defaultElem = doc.createElement( QStringLiteral( "default" ) );
defaultElem.setAttribute( QStringLiteral( "field" ), field.name() );
defaultElem.setAttribute( QStringLiteral( "expression" ), field.defaultValue().expression() );
defaultElem.setAttribute( QStringLiteral( "applyOnUpdate" ), field.defaultValue().applyOnUpdate() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
defaultElem.setAttribute( QStringLiteral( "expression" ), field.defaultValueDefinition().expression() );
defaultElem.setAttribute( QStringLiteral( "applyOnUpdate" ), field.defaultValueDefinition().applyOnUpdate() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
defaultsElem.appendChild( defaultElem );
}
node.appendChild( defaultsElem );
Expand Down Expand Up @@ -2961,7 +2961,7 @@ void QgsVectorLayer::updateFields()
if ( index < 0 )
continue;

mFields[ index ].setDefaultValue( defaultIt.value() );
mFields[ index ].setDefaultValueDefinition( defaultIt.value() );
if ( defaultIt.value().applyOnUpdate() )
mDefaultValueOnUpdateFields.insert( index );
}
Expand Down Expand Up @@ -3042,7 +3042,8 @@ QVariant QgsVectorLayer::defaultValue( int index, const QgsFeature &feature, Qgs
if ( index < 0 || index >= mFields.count() )
return QVariant();

QString expression = mFields.at( index ).defaultValue().expression();
QString expression = mFields.at( index ).defaultValueDefinition().expression();
qWarning() << "DEFAUL TVALUE" << expression;
if ( expression.isEmpty() )
return mDataProvider->defaultValue( index );

Expand Down Expand Up @@ -3090,11 +3091,11 @@ void QgsVectorLayer::setDefaultValueDefinition( int index, const QgsDefaultValue

if ( definition.isValid() )
{
mDefaultExpressionMap.remove( mFields.at( index ).name() );
mDefaultExpressionMap.insert( mFields.at( index ).name(), definition );
}
else
{
mDefaultExpressionMap.insert( mFields.at( index ).name(), definition );
mDefaultExpressionMap.remove( mFields.at( index ).name() );
}
updateFields();
}
Expand All @@ -3104,7 +3105,7 @@ QgsDefaultValue QgsVectorLayer::defaultValueDefinition( int index ) const
if ( index < 0 || index >= mFields.count() )
return QString();
else
return mFields.at( index ).defaultValue().expression();
return mFields.at( index ).defaultValueDefinition().expression();
}

QSet<QVariant> QgsVectorLayer::uniqueValues( int index, int limit ) const
Expand Down

0 comments on commit f0b7149

Please sign in to comment.