Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #10703 (selection reset after added/removed attribute)
- Loading branch information
Showing
1 changed file
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wonder-sk
Author
Member
|
||
// 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(); | ||
|
TODO: handle add/removal of joins without reset?