Skip to content
Permalink
Browse files
Fix NULL value for relation reference widget
  • Loading branch information
m-kuhn committed Jun 24, 2014
1 parent 2fedba0 commit 2934bcdfaafe3db8a59f2f900fc91b211985f4a1
Showing with 24 additions and 9 deletions.
  1. +23 −8 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
  2. +1 −1 src/gui/qgsattributeform.cpp
@@ -77,6 +77,11 @@ void QgsRelationReferenceWidget::initWidget( QWidget* editor )

if ( relation.isValid() )
{
if ( config( "AllowNULL" ).toBool() )
{
mComboBox->addItem( tr( "(no selection)" ), QVariant( field().type() ) );
}

mReferencedLayer = relation.referencedLayer();
int refFieldIdx = mReferencedLayer->fieldNameIndex( relation.fieldPairs().first().second );

@@ -95,11 +100,6 @@ void QgsRelationReferenceWidget::initWidget( QWidget* editor )
mFidFkMap.insert( f.id(), f.attribute( refFieldIdx ) );
}

if ( config( "AllowNULL" ).toBool() )
{
mComboBox->addItem( "[NULL]" );
}

// Only connect after iterating, to have only one iterator on the referenced table at once
connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( referenceChanged( int ) ) );
}
@@ -119,7 +119,7 @@ QVariant QgsRelationReferenceWidget::value()
QVariant varFid = mComboBox->itemData( mComboBox->currentIndex() );
if ( varFid.isNull() )
{
return QVariant();
return QVariant( field().type() );
}
else
{
@@ -129,9 +129,24 @@ QVariant QgsRelationReferenceWidget::value()

void QgsRelationReferenceWidget::setValue( const QVariant& value )
{
QgsFeatureId fid = mFidFkMap.key( value );
int oldIdx = mComboBox->currentIndex();
mComboBox->setCurrentIndex( mComboBox->findData( fid ) );

if ( value.isNull() )
{
if ( config( "AllowNULL" ).toBool() )
{
mComboBox->setCurrentIndex( 0 );
}
else
{
mComboBox->setCurrentIndex( -1 );
}
}
else
{
QgsFeatureId fid = mFidFkMap.key( value );
mComboBox->setCurrentIndex( mComboBox->findData( fid ) );
}

if ( !mInitialValueAssigned )
{
@@ -155,7 +155,7 @@ bool QgsAttributeForm::save()
QVariant srcVar = eww->value();
if ( dstVar != srcVar && srcVar.isValid() )
{
dst[eww->fieldIdx()] = eww->value();
dst[eww->fieldIdx()] = srcVar;

doUpdate = true;
}

0 comments on commit 2934bcd

Please sign in to comment.