Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fields of non existent joined features are set to NULL
  • Loading branch information
pblottiere committed Jul 3, 2017
1 parent 257f35c commit 5253aa8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 13 additions & 13 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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;
Expand All @@ -1960,23 +1950,33 @@ 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 )
{
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
{
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 );
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/gui/qgsattributeform.h
Expand Up @@ -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
Expand Down

0 comments on commit 5253aa8

Please sign in to comment.