Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid crash with invalid relation
  • Loading branch information
m-kuhn committed Nov 20, 2017
1 parent f084fc0 commit 7fb3a4e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsaggregatecalculator.h
Expand Up @@ -46,7 +46,7 @@ class CORE_EXPORT QgsAggregateCalculator
/**
* Structured information about the available aggregates.
*
* \since QGIS 3.0
* \since QGIS 3.2
*/
struct AggregateInfo
{
Expand Down
25 changes: 20 additions & 5 deletions src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp
Expand Up @@ -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" );
Expand All @@ -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()
Expand Down
Expand Up @@ -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.