Skip to content

Commit f76cb58

Browse files
authored
Merge pull request #6536 from m-kuhn/searchWidgetRecursionTrap
Avoid freezing attribute form with recursion
2 parents 734ea37 + e969584 commit f76cb58

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

python/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Constructor
4242

4343
virtual void setExpression( const QString &value );
4444

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

4647
};
4748

src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ QWidget *QgsRelationAggregateSearchWidgetWrapper::createWidget( QWidget *parent
6161
}
6262
else
6363
{
64-
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
65-
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, parent );
66-
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
67-
widget = mAttributeForm;
64+
mContainerWidget = new QWidget( parent );
65+
widget = mContainerWidget;
66+
widget->installEventFilter( this );
6867
}
6968

7069
groupBox->setLayout( new QGridLayout() );
@@ -83,3 +82,19 @@ void QgsRelationAggregateSearchWidgetWrapper::setExpression( const QString &valu
8382
Q_UNUSED( value )
8483
QgsDebugMsg( "Not supported" );
8584
}
85+
86+
bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEvent *event )
87+
{
88+
bool rv = QgsSearchWidgetWrapper::eventFilter( watched, event );
89+
if ( event->type() == QEvent::Show && !mAttributeForm )
90+
{
91+
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
92+
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget );
93+
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
94+
QGridLayout *glayout = new QGridLayout();
95+
mContainerWidget->setLayout( glayout );
96+
glayout->setMargin( 0 );
97+
glayout->addWidget( mAttributeForm );
98+
}
99+
return rv;
100+
}

src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ class GUI_EXPORT QgsRelationAggregateSearchWidgetWrapper : public QgsSearchWidge
4949
QWidget *createWidget( QWidget *parent ) override;
5050
bool applyDirectly() override;
5151
void setExpression( const QString &value ) override;
52+
virtual bool eventFilter( QObject *watched, QEvent *event ) override;
5253

5354
private:
5455
QgsRelationWidgetWrapper *mWrapper = nullptr;
5556
QgsAttributeForm *mAttributeForm = nullptr;
57+
QWidget *mContainerWidget = nullptr;
5658
};
5759

5860
#endif // QGSRELATIONAGGREGATESEARCHWIDGETWRAPPER_H

src/gui/qgsattributeformrelationeditorwidget.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ QgsAttributeFormRelationEditorWidget::QgsAttributeFormRelationEditorWidget( QgsR
2828

2929
void QgsAttributeFormRelationEditorWidget::createSearchWidgetWrappers( const QgsAttributeEditorContext &context )
3030
{
31-
Q_UNUSED( context )
32-
mSearchWidget = new QgsRelationAggregateSearchWidgetWrapper( layer(), mWrapper, form() );
31+
if ( context.parentContext() )
32+
{
33+
mSearchWidget = new QgsRelationAggregateSearchWidgetWrapper( layer(), mWrapper, form() );
34+
mSearchWidget->setContext( context );
3335

34-
setSearchWidgetWrapper( mSearchWidget );
36+
setSearchWidgetWrapper( mSearchWidget );
37+
}
3538
}
3639

3740
QString QgsAttributeFormRelationEditorWidget::currentFilterExpression() const

0 commit comments

Comments
 (0)