Skip to content
Permalink
Browse files

Set missing nm relation for QgsAbstractRelationEditorConfigWidget

This is needed to let QgsAbstractRelationEditorConfigWidget
implementations know which nm cardinality is choosen if any.
  • Loading branch information
domi4484 committed Mar 22, 2021
1 parent a691491 commit c087063356fd9a86f045886a107a09eb9354a912
@@ -316,6 +316,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 config: 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, QOverload<int>::of( &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() );
@@ -651,6 +651,16 @@ QgsRelation QgsAbstractRelationEditorConfigWidget::relation() const
return mRelation;
}

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

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


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

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

/**
* \brief Set the nm relation for this widget.
*
* \param config 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 c087063

Please sign in to comment.