Skip to content

Commit

Permalink
final relation cardinality combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Nov 2, 2017
1 parent 9b670d0 commit 90546b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsattributerelationedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ QgsAttributeRelationEdit::~QgsAttributeRelationEdit()
{
}

void QgsAttributeRelationEdit::setCardinalityCombo( const QString &cardinalityComboItem )
void QgsAttributeRelationEdit::setCardinalityCombo( const QString &cardinalityComboItem, const QVariant &auserData )
{
coCardinality->addItem( cardinalityComboItem );
coCardinality->addItem( cardinalityComboItem, auserData );
}

void QgsAttributeRelationEdit::setCardinality( const QString &cardinality )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributerelationedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class APP_EXPORT QgsAttributeRelationEdit: public QWidget, private Ui::QgsAttrib
/**
* Setter for combo cardinality item
*/
void setCardinalityCombo( const QString &cardinalityComboItem );
void setCardinalityCombo( const QString &cardinalityComboItem, const QVariant &auserData = QVariant() );

/**
* Setter for combo cardinality
Expand Down
27 changes: 15 additions & 12 deletions src/app/qgsattributesformproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
}


void QgsAttributesFormProperties::storeAttributeTypeDialog()
{
void QgsAttributesFormProperties::storeAttributeTypeDialog(){
FieldConfig cfg;

cfg.mEditable = mAttributeTypeDialog->fieldEditable();
Expand Down Expand Up @@ -194,8 +193,17 @@ void QgsAttributesFormProperties::loadAttributeRelationEdit()
RelationConfig cfg = currentItem->data( 0, RelationConfigRole ).value<RelationConfig>();

mAttributeRelationEdit = new QgsAttributeRelationEdit( currentItem->data( 0, FieldNameRole ).toString(), mAttributeTypeFrame );
mAttributeRelationEdit->setCardinalityCombo( "testoption 1" );
mAttributeRelationEdit->setCardinalityCombo( "testoption 2" );

mAttributeRelationEdit->setCardinalityCombo( tr( "Many to one relation" ) );

QgsRelation relation = QgsProject::instance()->relationManager()->relation( currentItem->data( 0, FieldNameRole ).toString() );

Q_FOREACH ( const QgsRelation &nmrel, QgsProject::instance()->relationManager()->referencingRelations( relation.referencingLayer() ) )
{
if ( nmrel.fieldPairs().at( 0 ).referencingField() != relation.fieldPairs().at( 0 ).referencingField() )
mAttributeRelationEdit->setCardinalityCombo( QStringLiteral( "%1 (%2)" ).arg( nmrel.referencedLayer()->name(), nmrel.fieldPairs().at( 0 ).referencedField() ), nmrel.id() );
}

mAttributeRelationEdit->setCardinality( cfg.mCardinality );

mAttributeRelationEdit->layout()->setMargin( 0 );
Expand Down Expand Up @@ -501,14 +509,9 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid

void QgsAttributesFormProperties::apply()
{
if ( mAttributeTypeDialog )
{
storeAttributeTypeDialog();
}
else
{
storeAttributeRelationEdit();
}

storeAttributeTypeDialog();
storeAttributeRelationEdit();

QgsEditFormConfig editFormConfig = mLayer->editFormConfig();

Expand Down

0 comments on commit 90546b0

Please sign in to comment.