@@ -30,7 +30,10 @@ QgsRelationAggregateSearchWidgetWrapper::QgsRelationAggregateSearchWidgetWrapper
30
30
31
31
QString QgsRelationAggregateSearchWidgetWrapper::expression () const
32
32
{
33
- QString aggregateFilter = mAttributeForm ->aggregateFilter ();
33
+ QString aggregateFilter;
34
+
35
+ if ( mAttributeForm )
36
+ aggregateFilter = mAttributeForm ->aggregateFilter ();
34
37
35
38
if ( aggregateFilter.isEmpty () )
36
39
return QStringLiteral ( " TRUE" );
@@ -45,10 +48,22 @@ bool QgsRelationAggregateSearchWidgetWrapper::valid() const
45
48
46
49
QWidget *QgsRelationAggregateSearchWidgetWrapper::createWidget ( QWidget *parent )
47
50
{
48
- QgsAttributeEditorContext subContext = QgsAttributeEditorContext ( context (), mWrapper ->relation (), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
49
- mAttributeForm = new QgsAttributeForm ( mWrapper ->relation ().referencingLayer (), QgsFeature (), subContext, parent );
50
- mAttributeForm ->setMode ( QgsAttributeForm::AggregateSearchMode );
51
- return mAttributeForm ;
51
+ QWidget *widget;
52
+ QgsRelation relation = mWrapper ->relation ();
53
+
54
+ if ( !relation.isValid () )
55
+ {
56
+ widget = new QLabel ( tr ( " Relation not valid" ) );
57
+ }
58
+ else
59
+ {
60
+ QgsAttributeEditorContext subContext = QgsAttributeEditorContext ( context (), mWrapper ->relation (), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
61
+ mAttributeForm = new QgsAttributeForm ( mWrapper ->relation ().referencingLayer (), QgsFeature (), subContext, parent );
62
+ mAttributeForm ->setMode ( QgsAttributeForm::AggregateSearchMode );
63
+ widget = mAttributeForm ;
64
+ }
65
+
66
+ return widget;
52
67
}
53
68
54
69
bool QgsRelationAggregateSearchWidgetWrapper::applyDirectly ()
0 commit comments