Skip to content

Commit

Permalink
Fix #10703 (selection reset after added/removed attribute)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 27, 2014
1 parent 2016b30 commit ae9b306
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/gui/qgsfieldmodel.cpp
Expand Up @@ -86,8 +86,59 @@ void QgsFieldModel::updateModel()
{
if ( mLayer )
{
if ( mFields.toList() != mLayer->pendingFields().toList() )
QgsFields newFields = mLayer->pendingFields();
if ( mFields.toList() != newFields.toList() )
{
// Try to handle two special cases: addition of a new field and removal of a field.

This comment has been minimized.

Copy link
@jef-n

jef-n Jun 27, 2014

Member

TODO: handle add/removal of joins without reset?

This comment has been minimized.

Copy link
@wonder-sk

wonder-sk Jun 27, 2014

Author Member

Ah... true. I don't think I will have time today to fix that :-(

// It would be better to listen directly to attributeAdded/attributeDeleted
// so we would not have to check for addition/removal here.

if ( mFields.count() == newFields.count() - 1 )
{
QgsFields tmpNewFields = newFields;
tmpNewFields.remove( tmpNewFields.count() - 1 );
if ( mFields.toList() == tmpNewFields.toList() )
{
// the only change is a new field at the end
beginInsertRows( QModelIndex(), mFields.count(), mFields.count() );
mFields = newFields;
endInsertRows();
return;
}
}

if ( mFields.count() == newFields.count() + 1 )
{
QgsFields tmpOldFields = mFields;
tmpOldFields.remove( tmpOldFields.count() - 1 );
if ( tmpOldFields.toList() == newFields.toList() )
{
// the only change is a field removed at the end
beginRemoveRows( QModelIndex(), mFields.count() - 1, mFields.count() - 1 );
mFields = newFields;
endRemoveRows();
return;
}

for ( int i = 0; i < newFields.count(); ++i )
{
if ( mFields.at( i ) != newFields.at( i ) )
{
QgsFields tmpOldFields = mFields;
tmpOldFields.remove( i );
if ( tmpOldFields.toList() != newFields.toList() )
break; // the change is more complex - go with general case

// the only change is a field removed at index i
beginRemoveRows( QModelIndex(), i, i );
mFields = newFields;
endRemoveRows();
return;
}
}
}

// general case with reset - not good - resets selections
beginResetModel();
mFields = mLayer->pendingFields();
endResetModel();
Expand Down

0 comments on commit ae9b306

Please sign in to comment.