Skip to content

Commit 5f157a9

Browse files
committed
offer NULL value in relation reference widget if allowed (fixes #14162)
1 parent 17f20bb commit 5f157a9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/gui/attributetable/qgsfeaturelistmodel.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const
6161
{
6262
return QSettings().value( "qgis/nullValue", "NULL" ).toString();
6363
}
64-
else
64+
else if ( role == QgsAttributeTableModel::FeatureIdRole )
6565
{
6666
return QVariant( QVariant::Int );
6767
}
68+
else
69+
{
70+
return QVariant( QVariant::Invalid );
71+
}
6872
}
6973

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

123127
Qt::ItemFlags QgsFeatureListModel::flags( const QModelIndex &index ) const
124128
{
125-
return sourceModel()->flags( mapToSource( index ) ) & ~Qt::ItemIsEditable;
129+
if ( mInjectNull && index.row() == 0 )
130+
{
131+
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
132+
}
133+
else
134+
{
135+
return sourceModel()->flags( mapToSource( index ) ) & ~Qt::ItemIsEditable;
136+
}
126137
}
127138

128139
void QgsFeatureListModel::setInjectNull( bool injectNull )

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ void QgsRelationReferenceWidget::init()
535535
}
536536
}
537537

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

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

0 commit comments

Comments
 (0)