Skip to content
Permalink
Browse files

Add safety guard

Fixes a crash if a widget is configured for an inexistent field
  • Loading branch information
m-kuhn committed Jun 10, 2020
1 parent 7d58502 commit 7cb484cfc3eaae1224f4a688e044dfb6074cee35
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/gui/qgsattributeform.cpp
@@ -1485,13 +1485,17 @@ void QgsAttributeForm::init()
if ( widgDef->type() == QgsAttributeEditorElement::AttributeEditorType::AeTypeField )
{
const QgsAttributeEditorField *fieldElement { static_cast<QgsAttributeEditorField *>( widgDef ) };
const QString fieldName { mLayer->fields().at( fieldElement->idx() ).name() };
if ( mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).hasProperty( QgsEditFormConfig::DataDefinedProperty::Alias ) )
const int fieldIdx = fieldElement->idx();
if ( fieldIdx >= 0 && fieldIdx < mLayer->fields().count() )
{
const QgsProperty property { mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).property( QgsEditFormConfig::DataDefinedProperty::Alias ) };
if ( property.isActive() && ! property.expressionString().isEmpty() )
const QString fieldName { mLayer->fields().at( fieldIdx ).name() };
if ( mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).hasProperty( QgsEditFormConfig::DataDefinedProperty::Alias ) )
{
mLabelDataDefinedProperties[ label ] = property;
const QgsProperty property { mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).property( QgsEditFormConfig::DataDefinedProperty::Alias ) };
if ( property.isActive() && ! property.expressionString().isEmpty() )
{
mLabelDataDefinedProperties[ label ] = property;
}
}
}
}

0 comments on commit 7cb484c

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