mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-23 00:05:43 -04:00
offer NULL value in relation reference widget if allowed (fixes #14162)
This commit is contained in:
parent
17f20bbb36
commit
5f157a9033
@ -61,10 +61,14 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const
|
|||||||
{
|
{
|
||||||
return QSettings().value( "qgis/nullValue", "NULL" ).toString();
|
return QSettings().value( "qgis/nullValue", "NULL" ).toString();
|
||||||
}
|
}
|
||||||
else
|
else if ( role == QgsAttributeTableModel::FeatureIdRole )
|
||||||
{
|
{
|
||||||
return QVariant( QVariant::Int );
|
return QVariant( QVariant::Int );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QVariant( QVariant::Invalid );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
if ( role == Qt::DisplayRole || role == Qt::EditRole )
|
||||||
@ -122,7 +126,14 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const
|
|||||||
|
|
||||||
Qt::ItemFlags QgsFeatureListModel::flags( const QModelIndex &index ) 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 )
|
void QgsFeatureListModel::setInjectNull( bool injectNull )
|
||||||
|
@ -535,7 +535,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
|
// Only connect after iterating, to have only one iterator on the referenced table at once
|
||||||
connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboReferenceChanged( int ) ) );
|
connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboReferenceChanged( int ) ) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user