Skip to content

Commit

Permalink
Merge pull request #42296 from domi4484/fixNmRelationMissing (#42543)
Browse files Browse the repository at this point in the history
Fix QgsAbstractRelationEditorWidget inconsistency NmRelation / NmRelationId

Co-authored-by: Matthias Kuhn <matthias@opengis.ch>
  • Loading branch information
github-actions[bot] and m-kuhn committed Mar 29, 2021
1 parent 0d261d2 commit 9164e04
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgsabstractrelationeditorwidget.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/gui/qgsabstractrelationeditorwidget.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -226,7 +232,6 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
bool mLayerInSameTransactionGroup = false;

bool mForceSuppressFormPopup = false;
QVariant mNmRelationId;
QString mLabel;

/**
Expand Down

0 comments on commit 9164e04

Please sign in to comment.