Skip to content
Permalink
Browse files

Avoid crash with invalid relation

  • Loading branch information
m-kuhn committed Nov 20, 2017
1 parent f084fc0 commit 7fb3a4eb66cc85abe2f7f33ae136a7a1a08a74ed
@@ -46,7 +46,7 @@ class CORE_EXPORT QgsAggregateCalculator
/**
* Structured information about the available aggregates.
*
* \since QGIS 3.0
* \since QGIS 3.2
*/
struct AggregateInfo
{
@@ -30,7 +30,10 @@ QgsRelationAggregateSearchWidgetWrapper::QgsRelationAggregateSearchWidgetWrapper

QString QgsRelationAggregateSearchWidgetWrapper::expression() const
{
QString aggregateFilter = mAttributeForm->aggregateFilter();
QString aggregateFilter;

if ( mAttributeForm )
aggregateFilter = mAttributeForm->aggregateFilter();

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

QWidget *QgsRelationAggregateSearchWidgetWrapper::createWidget( QWidget *parent )
{
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, parent );
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
return mAttributeForm;
QWidget *widget;
QgsRelation relation = mWrapper->relation();

if ( !relation.isValid() )
{
widget = new QLabel( tr( "Relation not valid" ) );
}
else
{
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, parent );
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
widget = mAttributeForm;
}

return widget;
}

bool QgsRelationAggregateSearchWidgetWrapper::applyDirectly()
@@ -51,10 +51,8 @@ class GUI_EXPORT QgsRelationAggregateSearchWidgetWrapper : public QgsSearchWidge
virtual void setExpression( const QString &value ) override;

private:
QgsRelationWidgetWrapper *mWrapper;
QgsAttributeForm *mAttributeForm;


QgsRelationWidgetWrapper *mWrapper = nullptr;
QgsAttributeForm *mAttributeForm = nullptr;
};

#endif // QGSRELATIONAGGREGATESEARCHWIDGETWRAPPER_H

0 comments on commit 7fb3a4e

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