Fields of non existent joined features are set to NULL

This commit is contained in:
Blottiere Paul 2017-07-03 19:19:32 +02:00
parent 257f35c46f
commit 5253aa80e2
2 changed files with 13 additions and 15 deletions

View File

@ -1936,16 +1936,6 @@ void QgsAttributeForm::ContainerInformation::apply( QgsExpressionContext *expres
}
}
QgsFeature QgsAttributeForm::joinedFeature( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const
{
QgsFeature joinedFeature = mLayer->joinBuffer()->joinedFeatureOf( info, feature );
if ( !joinedFeature.isValid() )
joinedFeature = QgsVectorLayerUtils::createFeature( info->joinLayer(), QgsGeometry(), QgsAttributeMap() );
return joinedFeature;
}
void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
{
QgsFeature formFeature;
@ -1960,7 +1950,7 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
if ( !info->isDynamicFormEnabled() )
continue;
QgsFeature joinFeature = joinedFeature( info, formFeature );
QgsFeature joinFeature = mLayer->joinBuffer()->joinedFeatureOf( info, formFeature );
QStringList *subsetFields = info->joinFieldNamesSubset();
if ( subsetFields )
@ -1968,7 +1958,12 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
Q_FOREACH ( const QString &field, *subsetFields )
{
QString prefixedName = info->prefixedFieldName( field );
changeAttribute( prefixedName, joinFeature.attribute( field ) );
QVariant val;
if ( joinFeature.isValid() )
val = joinFeature.attribute( field );
changeAttribute( prefixedName, val );
}
}
else
@ -1976,7 +1971,12 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
Q_FOREACH ( const QgsField &field, joinFeature.fields() )
{
QString prefixedName = info->prefixedFieldName( field );
changeAttribute( prefixedName, joinFeature.attribute( field.name() ) );
QVariant val;
if ( joinFeature.isValid() )
val = joinFeature.attribute( field.name() );
changeAttribute( prefixedName, val );
}
}
}

View File

@ -273,8 +273,6 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
void initPython();
QgsFeature joinedFeature( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;
void updateJoinedFields( const QgsEditorWidgetWrapper &eww );
struct WidgetInfo