mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Avoid freezing attribute form with recursion
The search widget wrappers for relations have two issues
* They recursively load whatever relations are defined. With self-referencing this leads to 💀
This is addressed by only loading one level of relations in search widgets.
* They would load even when hidden, leading to long load times on attribute table opening.
We now only actually load the form on the show event
This commit is contained in:
parent
283f3b8e33
commit
e969584ad9
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user