Skip to content

Commit

Permalink
Fix crash when setting value for relation widget wrapper (#41653)
Browse files Browse the repository at this point in the history
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 353b72c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.cpp
Expand Up @@ -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 )
Expand All @@ -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() )
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.h
Expand Up @@ -79,6 +79,7 @@ class GUI_EXPORT QgsRelationReferenceWidgetWrapper : public QgsEditorWidgetWrapp
QgsMapCanvas *mCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;
bool mIndeterminateState;
int mBlockChanges = 0;

};

Expand Down

0 comments on commit 353b72c

Please sign in to comment.