diff --git a/python/gui/auto_generated/qgsabstractrelationeditorwidget.sip.in b/python/gui/auto_generated/qgsabstractrelationeditorwidget.sip.in index ca61945e17aa..702bd3b55918 100644 --- a/python/gui/auto_generated/qgsabstractrelationeditorwidget.sip.in +++ b/python/gui/auto_generated/qgsabstractrelationeditorwidget.sip.in @@ -61,6 +61,13 @@ inserting and deleting entries on the intermediate table as required. %Docstring Returns the relation +.. versionadded:: 3.18 +%End + + QgsRelation nmRelation() const; +%Docstring +Returns the nm relation + .. versionadded:: 3.18 %End diff --git a/src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp b/src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp index 1b05818fe53f..9f5f02977884 100644 --- a/src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp @@ -268,8 +268,6 @@ void QgsRelationWidgetWrapper::setNmRelationId( const QVariant &nmRelationId ) { if ( mWidget ) { - mWidget->setNmRelationId( nmRelationId ); - mNmRelation = QgsProject::instance()->relationManager()->relation( nmRelationId.toString() ); // If this widget is already embedded by the same relation, reduce functionality diff --git a/src/gui/qgsabstractrelationeditorwidget.cpp b/src/gui/qgsabstractrelationeditorwidget.cpp index e6064b0e2687..944b39830c1b 100644 --- a/src/gui/qgsabstractrelationeditorwidget.cpp +++ b/src/gui/qgsabstractrelationeditorwidget.cpp @@ -22,6 +22,7 @@ #include "qgsfeature.h" #include "qgsfeatureselectiondlg.h" #include "qgsrelation.h" +#include "qgsrelationmanager.h" #include "qgspolymorphicrelation.h" #include "qgsvectorlayertools.h" #include "qgsproject.h" @@ -116,12 +117,16 @@ void QgsAbstractRelationEditorWidget::setFeature( const QgsFeature &feature, boo void QgsAbstractRelationEditorWidget::setNmRelationId( const QVariant &nmRelationId ) { - mNmRelationId = nmRelationId; + QgsRelation nmrelation = QgsProject::instance()->relationManager()->relation( nmRelationId.toString() ); + beforeSetRelations( mRelation, nmrelation ); + mNmRelation = nmrelation; + afterSetRelations(); + updateUi(); } QVariant QgsAbstractRelationEditorWidget::nmRelationId() const { - return mNmRelationId; + return mNmRelation.id(); } QString QgsAbstractRelationEditorWidget::label() const diff --git a/src/gui/qgsabstractrelationeditorwidget.h b/src/gui/qgsabstractrelationeditorwidget.h index a7f383918aea..a3e44a5a8ced 100644 --- a/src/gui/qgsabstractrelationeditorwidget.h +++ b/src/gui/qgsabstractrelationeditorwidget.h @@ -86,6 +86,12 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget */ QgsRelation relation() const {return mRelation;} + /** + * Returns the nm relation + * \since QGIS 3.18 + */ + QgsRelation nmRelation() const {return mNmRelation;} + /** * Sets the \a feature being edited and updates the UI unless \a update is set to FALSE */ @@ -226,7 +232,6 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget bool mLayerInSameTransactionGroup = false; bool mForceSuppressFormPopup = false; - QVariant mNmRelationId; QString mLabel; /**