Skip to content
Permalink
Browse files

Merge pull request #34428 from elpaso/bugfix-gh34404-crash-on-apply-d…

…efault-value

Fix crash when switching "apply default value on update"
  • Loading branch information
elpaso committed Feb 14, 2020
2 parents 9b03ada + 4d20809 commit 2a0aa0305cc20390cccc14b8bbb1e5e6e1433767
Showing with 38 additions and 26 deletions.
  1. +36 −26 src/gui/qgsattributeform.cpp
  2. +2 −0 src/gui/qgsattributeform.h
@@ -452,6 +452,10 @@ bool QgsAttributeForm::saveEdits()

bool QgsAttributeForm::updateDefaultValues( const int originIdx )
{

// Synchronize
updateDefaultValueDependencies();

if ( !mDefaultValueDependencies.contains( originIdx ) )
return false;

@@ -1558,32 +1562,7 @@ void QgsAttributeForm::init()
}
}

//create defaultValueDependencies
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
if ( eww )
{
QgsExpression exp( eww->field().defaultValueDefinition().expression() );
const QSet<QString> referencedColumns = exp.referencedColumns();
for ( const QString &referencedColumn : referencedColumns )
{
if ( referencedColumn == QgsFeatureRequest::ALL_ATTRIBUTES )
{
const QList<int> allAttributeIds( mLayer->fields().allAttributesList() );

for ( const int id : allAttributeIds )
{
mDefaultValueDependencies.insertMulti( id, eww );
}
}
else
{
mDefaultValueDependencies.insertMulti( mLayer->fields().lookupField( referencedColumn ), eww );
}
}
}
}
updateDefaultValueDependencies();

if ( !mButtonBox )
{
@@ -2415,6 +2394,37 @@ bool QgsAttributeForm::fieldIsEditable( int fieldIndex ) const
return QgsVectorLayerUtils::fieldIsEditable( mLayer, fieldIndex, mFeature );
}

void QgsAttributeForm::updateDefaultValueDependencies()
{
mDefaultValueDependencies.clear();
//create defaultValueDependencies
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
if ( eww )
{
QgsExpression exp( eww->field().defaultValueDefinition().expression() );
const QSet<QString> referencedColumns = exp.referencedColumns();
for ( const QString &referencedColumn : referencedColumns )
{
if ( referencedColumn == QgsFeatureRequest::ALL_ATTRIBUTES )
{
const QList<int> allAttributeIds( mLayer->fields().allAttributesList() );

for ( const int id : allAttributeIds )
{
mDefaultValueDependencies.insertMulti( id, eww );
}
}
else
{
mDefaultValueDependencies.insertMulti( mLayer->fields().lookupField( referencedColumn ), eww );
}
}
}
}
}

void QgsAttributeForm::updateIcon( QgsEditorWidgetWrapper *eww )
{
if ( !eww->widget() || !mIconMap[eww->widget()] )
@@ -333,6 +333,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget

bool fieldIsEditable( const QgsVectorLayer &layer, int fieldIndex, QgsFeatureId fid ) const;

void updateDefaultValueDependencies();

struct WidgetInfo
{
QWidget *widget = nullptr;

0 comments on commit 2a0aa03

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