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 authored and github-actions committed Feb 19, 2021
1 parent 6fea5c6 commit 19edc353d48d3c514b461841bac8dd50c707ff98
@@ -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 19edc35

Please sign in to comment.