Skip to content

Commit

Permalink
Merge pull request #6536 from m-kuhn/searchWidgetRecursionTrap
Browse files Browse the repository at this point in the history
Avoid freezing attribute form with recursion
  • Loading branch information
m-kuhn committed Mar 6, 2018
2 parents 734ea37 + e969584 commit f76cb58
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Expand Up @@ -42,6 +42,7 @@ Constructor

virtual void setExpression( const QString &value );

virtual bool eventFilter( QObject *watched, QEvent *event );

};

Expand Down
23 changes: 19 additions & 4 deletions src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp
Expand Up @@ -61,10 +61,9 @@ QWidget *QgsRelationAggregateSearchWidgetWrapper::createWidget( QWidget *parent
}
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;
mContainerWidget = new QWidget( parent );
widget = mContainerWidget;
widget->installEventFilter( this );
}

groupBox->setLayout( new QGridLayout() );
Expand All @@ -83,3 +82,19 @@ void QgsRelationAggregateSearchWidgetWrapper::setExpression( const QString &valu
Q_UNUSED( value )
QgsDebugMsg( "Not supported" );
}

bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEvent *event )
{
bool rv = QgsSearchWidgetWrapper::eventFilter( watched, event );
if ( event->type() == QEvent::Show && !mAttributeForm )
{
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget );
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
QGridLayout *glayout = new QGridLayout();
mContainerWidget->setLayout( glayout );
glayout->setMargin( 0 );
glayout->addWidget( mAttributeForm );
}
return rv;
}
Expand Up @@ -49,10 +49,12 @@ class GUI_EXPORT QgsRelationAggregateSearchWidgetWrapper : public QgsSearchWidge
QWidget *createWidget( QWidget *parent ) override;
bool applyDirectly() override;
void setExpression( const QString &value ) override;
virtual bool eventFilter( QObject *watched, QEvent *event ) override;

private:
QgsRelationWidgetWrapper *mWrapper = nullptr;
QgsAttributeForm *mAttributeForm = nullptr;
QWidget *mContainerWidget = nullptr;
};

#endif // QGSRELATIONAGGREGATESEARCHWIDGETWRAPPER_H
9 changes: 6 additions & 3 deletions src/gui/qgsattributeformrelationeditorwidget.cpp
Expand Up @@ -28,10 +28,13 @@ QgsAttributeFormRelationEditorWidget::QgsAttributeFormRelationEditorWidget( QgsR

void QgsAttributeFormRelationEditorWidget::createSearchWidgetWrappers( const QgsAttributeEditorContext &context )
{
Q_UNUSED( context )
mSearchWidget = new QgsRelationAggregateSearchWidgetWrapper( layer(), mWrapper, form() );
if ( context.parentContext() )
{
mSearchWidget = new QgsRelationAggregateSearchWidgetWrapper( layer(), mWrapper, form() );
mSearchWidget->setContext( context );

setSearchWidgetWrapper( mSearchWidget );
setSearchWidgetWrapper( mSearchWidget );
}
}

QString QgsAttributeFormRelationEditorWidget::currentFilterExpression() const
Expand Down

0 comments on commit f76cb58

Please sign in to comment.