Skip to content
Permalink
Browse files

Rename QgsField::defaultValue

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 f0b71499d1e5234813e5850be915d6ff4982eddf
Showing with 27 additions and 26 deletions.
  1. +4 −4 python/core/qgsfield.sip
  2. +7 −7 src/core/qgsfield.cpp
  3. +5 −5 src/core/qgsfield.h
  4. +3 −3 src/core/qgsfield_p.h
  5. +8 −7 src/core/qgsvectorlayer.cpp
@@ -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;
@@ -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 )
@@ -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 ) );
@@ -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 )
{
@@ -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:
@@ -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.
@@ -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 )
{
}
@@ -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 ) );
}

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

//! Default value
QgsDefaultValue defaultValue;
QgsDefaultValue defaultValueDefinition;

//! Field constraints
QgsFieldConstraints constraints;
@@ -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 );
@@ -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 );
}
@@ -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 );

@@ -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();
}
@@ -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

0 comments on commit f0b7149

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