Skip to content

Commit 7fb3a4e

Browse files
committedNov 20, 2017
Avoid crash with invalid relation
1 parent f084fc0 commit 7fb3a4e

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed
 

‎src/core/qgsaggregatecalculator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CORE_EXPORT QgsAggregateCalculator
4646
/**
4747
* Structured information about the available aggregates.
4848
*
49-
* \since QGIS 3.0
49+
* \since QGIS 3.2
5050
*/
5151
struct AggregateInfo
5252
{

‎src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ QgsRelationAggregateSearchWidgetWrapper::QgsRelationAggregateSearchWidgetWrapper
3030

3131
QString QgsRelationAggregateSearchWidgetWrapper::expression() const
3232
{
33-
QString aggregateFilter = mAttributeForm->aggregateFilter();
33+
QString aggregateFilter;
34+
35+
if ( mAttributeForm )
36+
aggregateFilter = mAttributeForm->aggregateFilter();
3437

3538
if ( aggregateFilter.isEmpty() )
3639
return QStringLiteral( "TRUE" );
@@ -45,10 +48,22 @@ bool QgsRelationAggregateSearchWidgetWrapper::valid() const
4548

4649
QWidget *QgsRelationAggregateSearchWidgetWrapper::createWidget( QWidget *parent )
4750
{
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;
5267
}
5368

5469
bool QgsRelationAggregateSearchWidgetWrapper::applyDirectly()

‎src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ class GUI_EXPORT QgsRelationAggregateSearchWidgetWrapper : public QgsSearchWidge
5151
virtual void setExpression( const QString &value ) override;
5252

5353
private:
54-
QgsRelationWidgetWrapper *mWrapper;
55-
QgsAttributeForm *mAttributeForm;
56-
57-
54+
QgsRelationWidgetWrapper *mWrapper = nullptr;
55+
QgsAttributeForm *mAttributeForm = nullptr;
5856
};
5957

6058
#endif // QGSRELATIONAGGREGATESEARCHWIDGETWRAPPER_H

0 commit comments

Comments
 (0)
Please sign in to comment.