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
Notes: sideshowbarker 2024-07-19 12:13:20 +09:00
3 changed files with 0 additions and 28 deletions

View file

@ -34,18 +34,6 @@ void GModel::did_update()
});
}
void GModel::set_selected_index(const GModelIndex& index)
{
if (m_selected_index == index)
return;
m_selected_index = index;
if (on_selection_changed)
on_selection_changed(index);
for_each_view([](auto& view) {
view.did_update_selection();
});
}
GModelIndex GModel::create_index(int row, int column, const void* data) const
{
return GModelIndex(*this, row, column, const_cast<void*>(data));

View file

@ -57,9 +57,6 @@ public:
return index.row() >= 0 && index.row() < row_count() && index.column() >= 0 && index.column() < column_count();
}
void set_selected_index(const GModelIndex&);
GModelIndex selected_index() const { return m_selected_index; }
virtual int key_column() const { return -1; }
virtual GSortOrder sort_order() const { return GSortOrder::None; }
virtual void set_key_column_and_sort_order(int, GSortOrder) {}
@ -80,7 +77,6 @@ protected:
private:
HashTable<GAbstractView*> m_views;
GModelIndex m_selected_index;
};
inline GModelIndex GModelIndex::parent() const

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();
}