Skip to content
Permalink
Browse files

Fix relation reference widget accidentally sets FK to NULL

  • Loading branch information
m-kuhn committed Jul 24, 2015
1 parent d01424a commit 4eaf8de75f59cdfe3cbfe9e559b72dccc9c2716a
Showing with 8 additions and 21 deletions.
  1. +8 −21 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
@@ -245,24 +245,12 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
if ( !mReferencedLayer )
return;

QgsFeatureIterator fit;
QgsAttributes attrs = QgsAttributes( mReferencingLayer->pendingFields().count() );
attrs[mFkeyFieldIdx] = value;

// TODO: Rewrite using expression
if ( mMasterModel )
{
fit = mMasterModel->layerCache()->getFeatures( QgsFeatureRequest() );
}
else
{
fit = mReferencedLayer->getFeatures( QgsFeatureRequest() );
}
while ( fit.nextFeature( mFeature ) )
{
if ( mFeature.attribute( mFkeyFieldIdx ) == value )
{
break;
}
}
QgsFeatureRequest request = mRelation.getReferencedFeatureRequest( attrs );

mReferencedLayer->getFeatures( request ).nextFeature( mFeature );

if ( !mFeature.isValid() )
{
@@ -284,7 +272,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
}
else
{
int i = mComboBox->findData( value, QgsAttributeTableModel::FeatureIdRole );
int i = mComboBox->findData( mFeature.id(), QgsAttributeTableModel::FeatureIdRole );
if ( i == -1 && mAllowNull )
{
mComboBox->setCurrentIndex( 0 );
@@ -358,10 +346,9 @@ QVariant QgsRelationReferenceWidget::foreignKey()
}
else
{
QVariant varFid = mComboBox->itemData( mComboBox->currentIndex(), QgsAttributeTableModel::FeatureIdRole );
if ( varFid.isNull() )
if ( !mFeature.isValid() )
{
return QVariant();
return QVariant( mReferencingLayer->pendingFields().at( mFkeyFieldIdx ).type() );
}
else
{

0 comments on commit 4eaf8de

Please sign in to comment.
You can’t perform that action at this time.