1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 03:02:07 +00:00

GModel: Remove selected_index() and set_selected_index()

This breaks GSortingProxyModel selection preservation across resorts.
I'm not yet sure how we're going to solve that, but it's going to have
to work a bit differently than before, since the model itself no longer
knows what's selected.

Selection is now managed by GModelSelection which allows us to select
any arbitrary number of items, and to have different selections in
different views onto the same model. Pretty sweet. :^)
This commit is contained in:
Andreas Kling 2019-09-07 21:38:13 +02:00
parent 6dec328af7
commit 2f5b2685af
3 changed files with 0 additions and 28 deletions

View file

@ -73,7 +73,6 @@ void GSortingProxyModel::set_key_column_and_sort_order(int column, GSortOrder so
void GSortingProxyModel::resort()
{
int previously_selected_target_row = map_to_target(selected_index()).row();
int row_count = target().row_count();
m_row_mappings.resize(row_count);
for (int i = 0; i < row_count; ++i)
@ -94,16 +93,5 @@ void GSortingProxyModel::resort()
is_less_than = data1 < data2;
return m_sort_order == GSortOrder::Ascending ? is_less_than : !is_less_than;
});
if (previously_selected_target_row != -1) {
// Preserve selection.
ASSERT(m_row_mappings.size() == row_count);
for (int i = 0; i < row_count; ++i) {
if (m_row_mappings[i] == previously_selected_target_row) {
set_selected_index(index(i, 0));
break;
}
}
}
did_update();
}