Skip to content

Commit

Permalink
support selecting NULL in relationreference search widget if allowNul…
Browse files Browse the repository at this point in the history
…l is active
  • Loading branch information
signedav authored and nyalldawson committed Sep 9, 2020
1 parent a89765e commit ab523df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -101,9 +101,17 @@ QString QgsRelationReferenceSearchWidgetWrapper::createExpression( QgsSearchWidg
case QVariant::ULongLong:
{
if ( flags & EqualTo )
{
if ( v.isNull() )
return fieldName + " IS NULL";
return fieldName + '=' + v.toString();
}
else if ( flags & NotEqualTo )
{
if ( v.isNull() )
return fieldName + " IS NOT NULL";
return fieldName + "<>" + v.toString();
}
break;
}

Expand Down Expand Up @@ -215,7 +223,7 @@ void QgsRelationReferenceSearchWidgetWrapper::initWidget( QWidget *editor )
// if no relation is given from the config, fetch one if there is only one available
if ( !relation.isValid() && !layer()->referencingRelations( mFieldIdx ).isEmpty() && layer()->referencingRelations( mFieldIdx ).count() == 1 )
relation = layer()->referencingRelations( mFieldIdx )[0];
mWidget->setRelation( relation, false );
mWidget->setRelation( relation, config( QStringLiteral( "AllowNULL" ) ).toBool() );

mWidget->showIndeterminateState();
connect( mWidget, &QgsRelationReferenceWidget::foreignKeysChanged, this, &QgsRelationReferenceSearchWidgetWrapper::onValuesChanged );
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -196,6 +196,7 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation &relation, bool
}
if ( mComboBox )
{
mComboBox->setAllowNull( mAllowNull );
mComboBox->setSourceLayer( mReferencedLayer );
mComboBox->setIdentifierFields( mReferencedFields );
}
Expand Down

0 comments on commit ab523df

Please sign in to comment.