Skip to content

Commit

Permalink
Avoid endless sub-RelationEditorWidget creation fix #42952 (#43246)
Browse files Browse the repository at this point in the history
* Avoid endless sub-RelationEditorWidget creation fix 42952

* Added missing docstring
  • Loading branch information
domi4484 committed May 17, 2021
1 parent 1107653 commit 40988a8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
Expand Up @@ -217,6 +217,11 @@ Duplicates features



void showEvent( QShowEvent * );
%Docstring
Refresh the UI when the widget becomes visible
%End

void updateTitle() /Deprecated/;
%Docstring
Updates the title contents to reflect the current state of the widget
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -181,8 +181,8 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
const QgsAttributeEditorContext *ctx = &context();
do
{
if ( ( ctx->relation().name() == mRelation.name() && ctx->formMode() == QgsAttributeEditorContext::Embed )
|| ( mNmRelation.isValid() && ctx->relation().name() == mNmRelation.name() ) )
if ( ( ctx->relation().id() == mRelation.id() && ctx->formMode() == QgsAttributeEditorContext::Embed )
|| ( mNmRelation.isValid() && ctx->relation().id() == mNmRelation.id() ) )
{
w->setVisible( false );
break;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsabstractrelationeditorwidget.cpp
Expand Up @@ -626,6 +626,11 @@ void QgsAbstractRelationEditorWidget::duplicateFeatures( const QgsFeatureIds &fi
}
}

void QgsAbstractRelationEditorWidget::showEvent( QShowEvent * )
{
updateUi();
}


///////////////////////////////////////////////////////////////////////////////

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsabstractrelationeditorwidget.h
Expand Up @@ -235,6 +235,11 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget

bool mForceSuppressFormPopup = false;

/**
* Refresh the UI when the widget becomes visible
*/
void showEvent( QShowEvent * );

/**
* Updates the title contents to reflect the current state of the widget
* \deprecated since QGIS 3.20 label is handled directly in QgsAttributeForm.
Expand Down
22 changes: 11 additions & 11 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -192,9 +192,14 @@ QgsRelationEditorWidget::QgsRelationEditorWidget( const QVariantMap &config, QWi
// add buttons layout
rootLayout->addLayout( buttonLayout );

mRelationLayout = new QGridLayout();
mRelationLayout->setContentsMargins( 0, 0, 0, 0 );
rootLayout->addLayout( mRelationLayout );
// add dual view
QGridLayout *relationLayout = new QGridLayout();
relationLayout->setContentsMargins( 0, 0, 0, 0 );
mDualView = new QgsDualView( this );
mDualView->setView( mViewMode );
connect( mDualView, &QgsDualView::showContextMenuExternally, this, &QgsRelationEditorWidget::showContextMenu );
relationLayout->addWidget( mDualView );
rootLayout->addLayout( relationLayout );

connect( mViewModeButtonGroup, static_cast<void ( QButtonGroup::* )( int )>( &QButtonGroup::buttonClicked ),
this, static_cast<void ( QgsRelationEditorWidget::* )( int )>( &QgsRelationEditorWidget::setViewMode ) );
Expand All @@ -214,14 +219,6 @@ QgsRelationEditorWidget::QgsRelationEditorWidget( const QVariantMap &config, QWi

void QgsRelationEditorWidget::initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request )
{
if ( !mDualView )
{
mDualView = new QgsDualView( this );
mDualView->setView( mViewMode );
connect( mDualView, &QgsDualView::showContextMenuExternally, this, &QgsRelationEditorWidget::showContextMenu );
mRelationLayout->addWidget( mDualView );
}

QgsAttributeEditorContext ctx { mEditorContext };
ctx.setParentFormFeature( mFeature );
mDualView->init( layer, mEditorContext.mapCanvas(), request, ctx );
Expand Down Expand Up @@ -365,6 +362,9 @@ void QgsRelationEditorWidget::updateUi()
if ( !mRelation.isValid() || !mFeature.isValid() )
return;

if ( !isVisible() )
return;

QgsFeatureRequest request = mRelation.getRelatedFeaturesRequest( mFeature );

if ( mNmRelation.isValid() )
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgsrelationeditorwidget.h
Expand Up @@ -225,7 +225,6 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
QToolButton *mFormViewButton = nullptr;
QToolButton *mTableViewButton = nullptr;
QToolButton *mAddFeatureGeometryButton = nullptr;
QGridLayout *mRelationLayout = nullptr;
QObjectUniquePtr<QgsMapToolDigitizeFeature> mMapToolDigitize;
QButtonGroup *mViewModeButtonGroup = nullptr;
QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
Expand Down

0 comments on commit 40988a8

Please sign in to comment.