Skip to content
Permalink
Browse files

Merge pull request #6536 from m-kuhn/searchWidgetRecursionTrap

Avoid freezing attribute form with recursion
  • Loading branch information
m-kuhn committed Mar 6, 2018
2 parents 734ea37 + e969584 commit f76cb58243c7fb4fa735b7d98d5980b7c1fbe754
@@ -42,6 +42,7 @@ Constructor

virtual void setExpression( const QString &value );

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

};

@@ -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() );
@@ -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;
}
@@ -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
@@ -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

0 comments on commit f76cb58

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