mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-11 00:04:27 -04:00
fix relation id confusion
if inserting a relation the id is used as name because it's used as identificator
This commit is contained in:
parent
14c057aeff
commit
901327c269
@ -115,7 +115,7 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()
|
||||
|
||||
for ( const QgsRelation &relation : relations )
|
||||
{
|
||||
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ) ); //relation.name() );
|
||||
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, QStringLiteral( "%1" ).arg( relation.id() ) );
|
||||
itemData.setShowLabel( true );
|
||||
|
||||
RelationConfig cfg( mLayer, relation.id() );
|
||||
@ -374,13 +374,14 @@ void QgsAttributesFormProperties::storeAttributeRelationEdit()
|
||||
}
|
||||
}
|
||||
|
||||
QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationName )
|
||||
QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationId )
|
||||
{
|
||||
QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
|
||||
while ( *itemIt )
|
||||
{
|
||||
QTreeWidgetItem *item = *itemIt;
|
||||
if ( item->data( 0, FieldNameRole ).toString() == relationName )
|
||||
|
||||
if ( item->data( 0, FieldNameRole ).toString() == relationId )
|
||||
return item->data( 0, RelationConfigRole ).value<RelationConfig>();
|
||||
++itemIt;
|
||||
}
|
||||
@ -407,13 +408,12 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
|
||||
case QgsAttributeEditorElement::AeTypeRelation:
|
||||
{
|
||||
const QgsAttributeEditorRelation *relationEditor = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
|
||||
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, widgetDef->name() );
|
||||
DnDTreeItemData itemData = DnDTreeItemData( DnDTreeItemData::Relation, relationEditor->relation().id());
|
||||
itemData.setShowLabel( widgetDef->showLabel() );
|
||||
RelationEditorConfiguration relEdConfig;
|
||||
relEdConfig.showLinkButton = relationEditor->showLinkButton();
|
||||
relEdConfig.showUnlinkButton = relationEditor->showUnlinkButton();
|
||||
itemData.setRelationEditorConfiguration( relEdConfig );
|
||||
|
||||
newWidget = tree->addItem( parent, itemData );
|
||||
break;
|
||||
}
|
||||
@ -531,7 +531,7 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
|
||||
case DnDTreeItemData::Relation:
|
||||
{
|
||||
QgsRelation relation = QgsProject::instance()->relationManager()->relation( itemData.name() );
|
||||
QgsAttributeEditorRelation *relDef = new QgsAttributeEditorRelation( itemData.name(), relation, parent );
|
||||
QgsAttributeEditorRelation *relDef = new QgsAttributeEditorRelation( relation, parent );
|
||||
relDef->setShowLinkButton( itemData.relationEditorConfiguration().showLinkButton );
|
||||
relDef->setShowUnlinkButton( itemData.relationEditorConfiguration().showUnlinkButton );
|
||||
widgetDef = relDef;
|
||||
@ -811,6 +811,7 @@ QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormPro
|
||||
}
|
||||
}
|
||||
newItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, data );
|
||||
|
||||
if ( index < 0 )
|
||||
parent->addChild( newItem );
|
||||
else
|
||||
|
@ -82,7 +82,7 @@ bool QgsAttributeEditorRelation::init( QgsRelationManager *relationManager )
|
||||
|
||||
QgsAttributeEditorElement *QgsAttributeEditorRelation::clone( QgsAttributeEditorElement *parent ) const
|
||||
{
|
||||
QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( name(), mRelationId, parent );
|
||||
QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( mRelationId, parent );
|
||||
element->mRelation = mRelation;
|
||||
element->mShowLinkButton = mShowLinkButton;
|
||||
element->mShowUnlinkButton = mShowUnlinkButton;
|
||||
|
@ -316,15 +316,35 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \deprecated since QGIS 3.0.2. The name parameter is not used for anything and overwritten by the relationId internally.
|
||||
*/
|
||||
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
|
||||
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
|
||||
, mRelationId( relationId )
|
||||
, mShowLinkButton( true )
|
||||
, mShowUnlinkButton( true )
|
||||
{}
|
||||
|
||||
/**
|
||||
* \deprecated since QGIS 3.0.2. The name parameter is not used for anything and overwritten by the relationId internally.
|
||||
*/
|
||||
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
|
||||
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
|
||||
, mRelationId( relation.id() )
|
||||
, mRelation( relation )
|
||||
, mShowLinkButton( true )
|
||||
, mShowUnlinkButton( true )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Creates a new element which embeds a relation.
|
||||
*
|
||||
* \param name The name of this element
|
||||
* \param relationId The id of the relation to embed
|
||||
* \param parent The parent (used as container)
|
||||
*/
|
||||
QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
|
||||
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
|
||||
QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent)
|
||||
: QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
|
||||
, mRelationId( relationId )
|
||||
, mShowLinkButton( true )
|
||||
, mShowUnlinkButton( true )
|
||||
@ -333,12 +353,11 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
|
||||
/**
|
||||
* Creates a new element which embeds a relation.
|
||||
*
|
||||
* \param name The name of this element
|
||||
* \param relation The relation to embed
|
||||
* \param parent The parent (used as container)
|
||||
*/
|
||||
QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
|
||||
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
|
||||
QgsAttributeEditorRelation( const QgsRelation &relation, QgsAttributeEditorElement *parent)
|
||||
: QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
|
||||
, mRelationId( relation.id() )
|
||||
, mRelation( relation )
|
||||
, mShowLinkButton( true )
|
||||
|
@ -550,8 +550,7 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme
|
||||
{
|
||||
// At this time, the relations are not loaded
|
||||
// So we only grab the id and delegate the rest to onRelationsLoaded()
|
||||
QString name = elem.attribute( QStringLiteral( "name" ) );
|
||||
QgsAttributeEditorRelation *relElement = new QgsAttributeEditorRelation( name, elem.attribute( QStringLiteral( "relation" ), QStringLiteral( "[None]" ) ), parent );
|
||||
QgsAttributeEditorRelation *relElement = new QgsAttributeEditorRelation( elem.attribute( QStringLiteral( "relation" ), QStringLiteral( "[None]" ) ), parent );
|
||||
relElement->setShowLinkButton( elem.attribute( QStringLiteral( "showLinkButton" ), QStringLiteral( "1" ) ).toInt() );
|
||||
relElement->setShowUnlinkButton( elem.attribute( QStringLiteral( "showUnlinkButton" ), QStringLiteral( "1" ) ).toInt() );
|
||||
newElement = relElement;
|
||||
|
Loading…
x
Reference in New Issue
Block a user