Skip to content

Commit

Permalink
Use id in gui if name is empty and crop layerid-part in the generated id
Browse files Browse the repository at this point in the history
The name can be empty, so use the id instead in the combo box. To avoid so long ids, the part taken from the layerid in the relation id is cropped to 10 signs. They are unique anyway because there is used a suffix counting up.
  • Loading branch information
signedav authored and m-kuhn committed Nov 14, 2017
1 parent ea5ed67 commit d4b2895
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsrelationmanagerdialog.cpp
Expand Up @@ -92,9 +92,9 @@ void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
QString relationId = addDlg.relationId();
if ( addDlg.relationId() == "" )
relationId = QString( "%1_%2_%3_%4" )
.arg( addDlg.referencingLayerId(),
.arg( addDlg.referencingLayerId().left( 10 ),
addDlg.references().at( 0 ).first,
addDlg.referencedLayerId(),
addDlg.referencedLayerId().left( 10 ),
addDlg.references().at( 0 ).second );

QStringList existingNames;
Expand Down
6 changes: 5 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp
Expand Up @@ -47,7 +47,11 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer* vl

Q_FOREACH ( const QgsRelation& relation, vl->referencingRelations( fieldIdx ) )
{
mComboRelation->addItem( QString( "%1 (%2)" ).arg( relation.name(), relation.referencedLayerId() ), relation.id() );
if ( relation.name().isEmpty() )
mComboRelation->addItem( QString( "%1 (%2)" ).arg( relation.id(), relation.referencedLayerId() ), relation.id() );
else
mComboRelation->addItem( QString( "%1 (%2)" ).arg( relation.name(), relation.referencedLayerId() ), relation.id() );

if ( relation.referencedLayer() )
{
mExpressionWidget->setField( relation.referencedLayer()->displayExpression() );
Expand Down

0 comments on commit d4b2895

Please sign in to comment.