Skip to content
Permalink
Browse files

Fix crash when setting value for relation widget wrapper (#41653)

Calling setForeignKeys during updateValues would result in the
widget wrapper catching the relation widget's changed signal,
triggering an assert as the foreign keys don't match the form's
feature's key (since that hasn't yet been set).

In any case, setting the initial value for a editor widget wrapper
must NOT be treated as a user-induced value change.
  • Loading branch information
nyalldawson committed Feb 19, 2021
1 parent 2d7f2d0 commit 353b72cabf26ac8fd723e38cd7c04f311dc2e911
@@ -204,8 +204,10 @@ void QgsRelationReferenceWidgetWrapper::updateValues( const QVariant &val, const
}
Q_ASSERT( values.count() == fieldPairs.count() );

mBlockChanges++;
mWidget->setForeignKeys( values );
mWidget->setFormFeature( formFeature() );
mBlockChanges--;
}

void QgsRelationReferenceWidgetWrapper::setEnabled( bool enabled )
@@ -218,6 +220,9 @@ void QgsRelationReferenceWidgetWrapper::setEnabled( bool enabled )

void QgsRelationReferenceWidgetWrapper::foreignKeysChanged( const QVariantList &values )
{
if ( mBlockChanges != 0 ) // initial value is being set, we can ignore this signal
return;

QVariant mainValue = QVariant( field().type() );

if ( !mWidget || !mWidget->relation().isValid() )
@@ -79,6 +79,7 @@ class GUI_EXPORT QgsRelationReferenceWidgetWrapper : public QgsEditorWidgetWrapp
QgsMapCanvas *mCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;
bool mIndeterminateState;
int mBlockChanges = 0;

};

0 comments on commit 353b72c

Please sign in to comment.