LibGUI: Add a way for models to update without invalidating indexes

This is really just a workaround to keep SystemMonitor's process table
working right wrt selection retention during resorts (while also doing
full index invalidation on things like ProfileViewer inversion.)

It's starting to feel like the model abstraction is not super great
and we'll need a better approach if we want to actually build some more
dynamic functionality into our views.
This commit is contained in:
Andreas Kling 2020-04-12 12:03:33 +02:00
parent 93f2a4edd3
commit 8e4751a963
Notes: sideshowbarker 2024-07-19 07:41:21 +09:00
17 changed files with 37 additions and 29 deletions

View file

@ -55,19 +55,22 @@ void AbstractView::set_model(RefPtr<Model> model)
m_model = move(model);
if (m_model)
m_model->register_view({}, *this);
did_update_model();
did_update_model(GUI::Model::InvalidateAllIndexes);
}
void AbstractView::did_update_model()
void AbstractView::did_update_model(unsigned flags)
{
// FIXME: It's unfortunate that we lose so much view state when the model updates in any way.
stop_editing();
m_edit_index = {};
m_hovered_index = {};
if (model()) {
selection().remove_matching([this](auto& index) { return !model()->is_valid(index); });
} else {
dbg() << "did_update_model, flags=" << flags;
dump_backtrace();
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
selection().clear();
} else {
selection().remove_matching([this](auto& index) { return !model()->is_valid(index); });
}
}