Skip to content

Commit 901327c

Browse files
committedMar 29, 2018
fix relation id confusion
if inserting a relation the id is used as name because it's used as identificator
1 parent 14c057a commit 901327c

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed
 

‎src/app/qgsattributesformproperties.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()
115115

116116
for ( const QgsRelation &relation : relations )
117117
{
118-
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ) ); //relation.name() );
118+
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ) );
119119
itemData.setShowLabel( true );
120120

121121
RelationConfig cfg( mLayer, relation.id() );
@@ -374,13 +374,14 @@ void QgsAttributesFormProperties::storeAttributeRelationEdit()
374374
}
375375
}
376376

377-
QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationName )
377+
QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationId )
378378
{
379379
QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
380380
while ( *itemIt )
381381
{
382382
QTreeWidgetItem *item = *itemIt;
383-
if ( item->data( 0, FieldNameRole ).toString() == relationName )
383+
384+
if ( item->data( 0, FieldNameRole ).toString() == relationId )
384385
return item->data( 0, RelationConfigRole ).value<RelationConfig>();
385386
++itemIt;
386387
}
@@ -407,13 +408,12 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
407408
case QgsAttributeEditorElement::AeTypeRelation:
408409
{
409410
const QgsAttributeEditorRelation *relationEditor = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
410-
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, widgetDef->name() );
411+
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, relationEditor->relation().id());
411412
itemData.setShowLabel( widgetDef->showLabel() );
412413
RelationEditorConfiguration relEdConfig;
413414
relEdConfig.showLinkButton = relationEditor->showLinkButton();
414415
relEdConfig.showUnlinkButton = relationEditor->showUnlinkButton();
415416
itemData.setRelationEditorConfiguration( relEdConfig );
416-
417417
newWidget = tree->addItem( parent, itemData );
418418
break;
419419
}
@@ -531,7 +531,7 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
531531
case DnDTreeItemData::Relation:
532532
{
533533
QgsRelation relation = QgsProject::instance()->relationManager()->relation( itemData.name() );
534-
QgsAttributeEditorRelation *relDef = new QgsAttributeEditorRelation( itemData.name(), relation, parent );
534+
QgsAttributeEditorRelation *relDef = new QgsAttributeEditorRelation( relation, parent );
535535
relDef->setShowLinkButton( itemData.relationEditorConfiguration().showLinkButton );
536536
relDef->setShowUnlinkButton( itemData.relationEditorConfiguration().showUnlinkButton );
537537
widgetDef = relDef;
@@ -811,6 +811,7 @@ QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormPro
811811
}
812812
}
813813
newItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, data );
814+
814815
if ( index < 0 )
815816
parent->addChild( newItem );
816817
else

‎src/core/qgsattributeeditorelement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool QgsAttributeEditorRelation::init( QgsRelationManager *relationManager )
8282

8383
QgsAttributeEditorElement *QgsAttributeEditorRelation::clone( QgsAttributeEditorElement *parent ) const
8484
{
85-
QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( name(), mRelationId, parent );
85+
QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( mRelationId, parent );
8686
element->mRelation = mRelation;
8787
element->mShowLinkButton = mShowLinkButton;
8888
element->mShowUnlinkButton = mShowUnlinkButton;

‎src/core/qgsattributeeditorelement.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,35 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
316316
{
317317
public:
318318

319+
/**
320+
* \deprecated since QGIS 3.0.2. The name parameter is not used for anything and overwritten by the relationId internally.
321+
*/
322+
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
323+
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
324+
, mRelationId( relationId )
325+
, mShowLinkButton( true )
326+
, mShowUnlinkButton( true )
327+
{}
328+
329+
/**
330+
* \deprecated since QGIS 3.0.2. The name parameter is not used for anything and overwritten by the relationId internally.
331+
*/
332+
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
333+
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
334+
, mRelationId( relation.id() )
335+
, mRelation( relation )
336+
, mShowLinkButton( true )
337+
, mShowUnlinkButton( true )
338+
{}
339+
319340
/**
320341
* Creates a new element which embeds a relation.
321342
*
322-
* \param name The name of this element
323343
* \param relationId The id of the relation to embed
324344
* \param parent The parent (used as container)
325345
*/
326-
QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
327-
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
346+
QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent)
347+
: QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
328348
, mRelationId( relationId )
329349
, mShowLinkButton( true )
330350
, mShowUnlinkButton( true )
@@ -333,12 +353,11 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
333353
/**
334354
* Creates a new element which embeds a relation.
335355
*
336-
* \param name The name of this element
337356
* \param relation The relation to embed
338357
* \param parent The parent (used as container)
339358
*/
340-
QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
341-
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
359+
QgsAttributeEditorRelation( const QgsRelation &relation, QgsAttributeEditorElement *parent)
360+
: QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
342361
, mRelationId( relation.id() )
343362
, mRelation( relation )
344363
, mShowLinkButton( true )

‎src/core/qgseditformconfig.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme
550550
{
551551
// At this time, the relations are not loaded
552552
// So we only grab the id and delegate the rest to onRelationsLoaded()
553-
QString name = elem.attribute( QStringLiteral( "name" ) );
554-
QgsAttributeEditorRelation *relElement = new QgsAttributeEditorRelation( name, elem.attribute( QStringLiteral( "relation" ), QStringLiteral( "[None]" ) ), parent );
553+
QgsAttributeEditorRelation *relElement = new QgsAttributeEditorRelation( elem.attribute( QStringLiteral( "relation" ), QStringLiteral( "[None]" ) ), parent );
555554
relElement->setShowLinkButton( elem.attribute( QStringLiteral( "showLinkButton" ), QStringLiteral( "1" ) ).toInt() );
556555
relElement->setShowUnlinkButton( elem.attribute( QStringLiteral( "showUnlinkButton" ), QStringLiteral( "1" ) ).toInt() );
557556
newElement = relElement;

0 commit comments

Comments
 (0)
Please sign in to comment.