Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2827 from SebDieBln/AllowNullInRelationRef
[Bugfix] offer NULL value in relation reference widget if allowed (fixes #14162)
  • Loading branch information
m-kuhn committed Mar 8, 2016
2 parents c6ebb8c + cc19a57 commit e08130d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/gui/attributetable/qgsfeaturelistmodel.cpp
Expand Up @@ -61,10 +61,14 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const
{
return QSettings().value( "qgis/nullValue", "NULL" ).toString();
}
else
else if ( role == QgsAttributeTableModel::FeatureIdRole )
{
return QVariant( QVariant::Int );
}
else
{
return QVariant( QVariant::Invalid );
}
}

if ( role == Qt::DisplayRole || role == Qt::EditRole )
Expand Down Expand Up @@ -122,7 +126,14 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const

Qt::ItemFlags QgsFeatureListModel::flags( const QModelIndex &index ) const
{
return sourceModel()->flags( mapToSource( index ) ) & ~Qt::ItemIsEditable;
if ( mInjectNull && index.row() == 0 )
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
else
{
return sourceModel()->flags( mapToSource( index ) ) & ~Qt::ItemIsEditable;
}
}

void QgsFeatureListModel::setInjectNull( bool injectNull )
Expand Down
10 changes: 7 additions & 3 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -234,7 +234,11 @@ void QgsRelationReferenceWidget::setRelationEditable( bool editable )

void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
{
if ( !value.isValid() || value.isNull() )
if ( !value.isValid() )
{
return;
}
if ( value.isNull() )
{
deleteForeignKey();
return;
Expand All @@ -254,7 +258,6 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )

if ( !mFeature.isValid() )
{
deleteForeignKey();
return;
}

Expand Down Expand Up @@ -535,7 +538,8 @@ void QgsRelationReferenceWidget::init()
}
}

mComboBox->setCurrentIndex( mComboBox->findData( mFeature.id(), QgsAttributeTableModel::FeatureIdRole ) );
QVariant featId = mFeature.isValid() ? mFeature.id() : QVariant( QVariant::Int );
mComboBox->setCurrentIndex( mComboBox->findData( featId, QgsAttributeTableModel::FeatureIdRole ) );

// Only connect after iterating, to have only one iterator on the referenced table at once
connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboReferenceChanged( int ) ) );
Expand Down

0 comments on commit e08130d

Please sign in to comment.