Skip to content
Permalink
Browse files

Merge pull request #42384 from domi4484/missingNmRelationQgsAbstractR…

…elationEditorConfigWidget

Set missing nm relation for QgsAbstractRelationEditorConfigWidget
  • Loading branch information
elpaso committed Mar 23, 2021
2 parents 803848a + a6ac61b commit 27d35a2495c264539da0bca74f4557afba6a74c5
@@ -323,6 +323,19 @@ Returns the relation for which this configuration widget applies
:return: The relation
%End

virtual void setNmRelation( const QgsRelation &nmRelation );
%Docstring
Set the nm relation for this widget.

:param nmRelation: The nm relation
%End

virtual QgsRelation nmRelation() const;
%Docstring
Returns the nm relation for which this configuration widget applies

:return: The nm relation
%End

};

@@ -100,11 +100,14 @@ QgsAttributeWidgetRelationEditWidget::QgsAttributeWidgetRelationEditWidget( QWid
it.next();
mWidgetTypeComboBox->addItem( it.value()->name(), it.key() );
}

connect( mRelationCardinalityCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributeWidgetRelationEditWidget::relationCardinalityComboCurrentIndexChanged );
}

void QgsAttributeWidgetRelationEditWidget::setRelationEditorConfiguration( const QgsAttributesFormProperties::RelationEditorConfiguration &config, const QString &relationId )
{
//load the combo mRelationCardinalityCombo
mRelationCardinalityCombo->clear();
setCardinalityCombo( tr( "Many to one relation" ) );

QgsRelation relation = QgsProject::instance()->relationManager()->relation( relationId );
@@ -163,6 +166,18 @@ QgsAttributesFormProperties::RelationEditorConfiguration QgsAttributeWidgetRelat
return relEdCfg;
}

void QgsAttributeWidgetRelationEditWidget::relationCardinalityComboCurrentIndexChanged( int index )
{
if ( index < 0 )
return;

if ( !mConfigWidget )
return;

QgsRelation nmRelation = QgsProject::instance()->relationManager()->relation( mRelationCardinalityCombo->currentData().toString() );
mConfigWidget->setNmRelation( nmRelation );
}

void QgsAttributeWidgetRelationEditWidget::setCardinalityCombo( const QString &cardinalityComboItem, const QVariant &auserData )
{
mRelationCardinalityCombo->addItem( cardinalityComboItem, auserData );
@@ -70,6 +70,9 @@ class GUI_EXPORT QgsAttributeWidgetRelationEditWidget : public QWidget, private

static QString title() { return tr( "Relation" ); }

private slots:
void relationCardinalityComboCurrentIndexChanged( int index );

private:
void setCardinalityCombo( const QString &cardinalityComboItem, const QVariant &auserData = QVariant() );
void setNmRelationId( const QVariant &auserData = QVariant() );
@@ -656,6 +656,16 @@ QgsRelation QgsAbstractRelationEditorConfigWidget::relation() const
return mRelation;
}

void QgsAbstractRelationEditorConfigWidget::setNmRelation( const QgsRelation &nmRelation )
{
mNmRelation = nmRelation;
}

QgsRelation QgsAbstractRelationEditorConfigWidget::nmRelation() const
{
return mNmRelation;
}


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

@@ -351,10 +351,24 @@ class GUI_EXPORT QgsAbstractRelationEditorConfigWidget : public QWidget
*/
QgsRelation relation() const;

/**
* \brief Set the nm relation for this widget.
*
* \param nmRelation The nm relation
*/
virtual void setNmRelation( const QgsRelation &nmRelation );

/**
* Returns the nm relation for which this configuration widget applies
*
* \returns The nm relation
*/
virtual QgsRelation nmRelation() const;

private:
QgsVectorLayer *mLayer = nullptr;
QgsRelation mRelation;
QgsRelation mNmRelation;
};


0 comments on commit 27d35a2

Please sign in to comment.