Skip to content
Permalink
Browse files
Be careful with requesting evaluated default values
We do not need a new evaluated value all the time

Fix #16545
  • Loading branch information
m-kuhn committed May 13, 2017
1 parent 7734d72 commit 60bbf67b08b0b3fc5d94653c69197c543042b877
@@ -234,9 +234,11 @@ class QgsVectorDataProvider : QgsDataProvider
const QMap<qint64, QgsGeometry> &geometry_map );

/**
* Returns the default value for field specified by @c fieldId
* Returns the default value for field specified by \a fieldId.
* If \a forceLazyEval is set to true, the provider the default value
* will not be evaluated on server side even if specified in the project properties.
*/
virtual QVariant defaultValue( int fieldId );
virtual QVariant defaultValue( int fieldId, bool forceLazyEval = false );

/**
* Changes geometries of existing features
@@ -531,9 +531,10 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
continue;
}

// _TAG
QString defVal;
if ( fields.fieldOrigin( i ) == QgsFields::OriginProvider && vlayer->dataProvider() )
defVal = vlayer->dataProvider()->defaultValue( fields.fieldOriginIndex( i ) ).toString();
defVal = vlayer->dataProvider()->defaultValue( fields.fieldOriginIndex( i ), true ).toString();

QString value = defVal == attrs.at( i ) ? defVal : fields.at( i ).displayString( attrs.at( i ) );
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << value );
@@ -93,8 +93,9 @@ bool QgsVectorDataProvider::changeAttributeValues( const QgsChangedAttributesMap
return false;
}

QVariant QgsVectorDataProvider::defaultValue( int fieldId )
QVariant QgsVectorDataProvider::defaultValue( int fieldId, bool forceLazyEval )
{
Q_UNUSED( forceLazyEval )
Q_UNUSED( fieldId );
return QVariant();
}
@@ -285,9 +285,11 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
const QgsGeometryMap &geometry_map );

/**
* Returns the default value for field specified by @c fieldId
* Returns the default value for field specified by \a fieldId.
* If \a forceLazyEval is set to true, the provider the default value
* will not be evaluated on server side even if specified in the project properties.
*/
virtual QVariant defaultValue( int fieldId );
virtual QVariant defaultValue( int fieldId, bool forceLazyEval = false );

/**
* Changes geometries of existing features
@@ -70,7 +70,7 @@ QString QgsEditorWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx

QString defVal;
if ( vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginProvider && vl->dataProvider() )
defVal = vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( fieldIdx ) ).toString();
defVal = vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( fieldIdx ), true ).toString();

return value == defVal ? defVal : vl->fields().at( fieldIdx ).displayString( value );
}
@@ -42,7 +42,11 @@ QgsField QgsEditorWidgetWrapper::field() const

QVariant QgsEditorWidgetWrapper::defaultValue() const
{
mDefaultValue = layer()->dataProvider()->defaultValue( mFieldIdx );
if ( !mDefaultValue.isValid() )
{
QgsVectorLayer* lyr = layer();
mDefaultValue = lyr->dataProvider()->defaultValue( lyr->fields().fieldOriginIndex( mFieldIdx ) );
}

return mDefaultValue;
}
@@ -515,8 +515,9 @@ void QgsGPXProvider::changeAttributeValues( QgsGPSObject& obj, const QgsAttribut
}


QVariant QgsGPXProvider::defaultValue( int fieldId )
QVariant QgsGPXProvider::defaultValue( int fieldId, bool forceLazyEval )
{
Q_UNUSED( forceLazyEval )
if ( fieldId == SrcAttr )
return tr( "Digitized in QGIS" );
return QVariant();
@@ -97,9 +97,11 @@ class QgsGPXProvider : public QgsVectorDataProvider
virtual int capabilities() const override;

/**
* Returns the default value for field specified by @c fieldId
* Returns the default value for field specified by \a fieldId.
* If \a forceLazyEval is set to true, the provider the default value
* will not be evaluated on server side even if specified in the project properties.
*/
virtual QVariant defaultValue( int fieldId ) override;
virtual QVariant defaultValue( int fieldId, bool forceLazyEval = false ) override;


/* Functions inherited from QgsDataProvider */
@@ -502,8 +502,10 @@ QString QgsMssqlProvider::quotedValue( const QVariant& value )
}
}

QVariant QgsMssqlProvider::defaultValue( int fieldId )
QVariant QgsMssqlProvider::defaultValue( int fieldId, bool forceLazyEval )
{
Q_UNUSED( forceLazyEval )

if ( mDefaultValues.contains( fieldId ) )
return mDefaultValues[fieldId];
else
@@ -231,8 +231,12 @@ class QgsMssqlProvider : public QgsVectorDataProvider
/** Convert values to quoted values for database work **/
static QString quotedValue( const QVariant& value );

/** Returns the default value for field specified by @c fieldId */
QVariant defaultValue( int fieldId ) override;
/**
* Returns the default value for field specified by \a fieldId.
* If \a forceLazyEval is set to true, the provider the default value
* will not be evaluated on server side even if specified in the project properties.
*/
virtual QVariant defaultValue( int fieldId, bool forceLazyEval = false ) override;

/** Import a vector layer into the database */
static QgsVectorLayerImport::ImportError createEmptyLayer(
@@ -1188,8 +1188,9 @@ bool QgsOracleProvider::isValid()
return mValid;
}

QVariant QgsOracleProvider::defaultValue( int fieldId )
QVariant QgsOracleProvider::defaultValue( int fieldId, bool forceLazyEval )
{
Q_UNUSED( forceLazyEval )
return mDefaultValues.value( fieldId, QVariant() );
}

@@ -182,8 +182,12 @@ class QgsOracleProvider : public QgsVectorDataProvider
/** Returns the default value for field specified by @c fieldName */
QVariant defaultValue( QString fieldName, QString tableName = QString::null, QString schemaName = QString::null );

/** Returns the default value for field specified by @c fieldId */
QVariant defaultValue( int fieldId ) override;
/**
* Returns the default value for field specified by \a fieldId.
* If \a forceLazyEval is set to true, the provider the default value
* will not be evaluated on server side even if specified in the project properties.
*/
virtual QVariant defaultValue( int fieldId, bool forceLazyEval = false ) override;

/** Adds a list of features
@return true in case of success and false in case of failure*/
@@ -1714,11 +1714,11 @@ bool QgsPostgresProvider::isValid()
return mValid;
}

QVariant QgsPostgresProvider::defaultValue( int fieldId )
QVariant QgsPostgresProvider::defaultValue( int fieldId, bool forceLazyEval )
{
QVariant defVal = mDefaultValues.value( fieldId, QString::null );
QVariant defVal = mDefaultValues.value( fieldId, QString() );

if ( providerProperty( EvaluateDefaultValues, false ).toBool() && !defVal.isNull() )
if ( providerProperty( EvaluateDefaultValues, false ).toBool() && !defVal.isNull() && !forceLazyEval )
{
const QgsField& fld = field( fieldId );

@@ -194,8 +194,12 @@ class QgsPostgresProvider : public QgsVectorDataProvider

QgsAttributeList pkAttributeIndexes() override { return mPrimaryKeyAttrs; }

/** Returns the default value for field specified by @c fieldId */
QVariant defaultValue( int fieldId ) override;
/**
* Returns the default value for field specified by \a fieldId.
* If \a forceLazyEval is set to true, the provider the default value
* will not be evaluated on server side even if specified in the project properties.
*/
virtual QVariant defaultValue( int fieldId , bool forceLazyEval = false ) override;

/** Adds a list of features
@return true in case of success and false in case of failure*/

0 comments on commit 60bbf67

Please sign in to comment.