mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
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. :^)
50 lines
1,010 B
C++
50 lines
1,010 B
C++
#include <LibGUI/GAbstractView.h>
|
|
#include <LibGUI/GModel.h>
|
|
|
|
GModel::GModel()
|
|
{
|
|
}
|
|
|
|
GModel::~GModel()
|
|
{
|
|
}
|
|
|
|
void GModel::register_view(Badge<GAbstractView>, GAbstractView& view)
|
|
{
|
|
m_views.set(&view);
|
|
}
|
|
|
|
void GModel::unregister_view(Badge<GAbstractView>, GAbstractView& view)
|
|
{
|
|
m_views.remove(&view);
|
|
}
|
|
|
|
void GModel::for_each_view(Function<void(GAbstractView&)> callback)
|
|
{
|
|
for (auto* view : m_views)
|
|
callback(*view);
|
|
}
|
|
|
|
void GModel::did_update()
|
|
{
|
|
if (on_update)
|
|
on_update();
|
|
for_each_view([](auto& view) {
|
|
view.did_update_model();
|
|
});
|
|
}
|
|
|
|
GModelIndex GModel::create_index(int row, int column, const void* data) const
|
|
{
|
|
return GModelIndex(*this, row, column, const_cast<void*>(data));
|
|
}
|
|
|
|
GModelIndex GModel::sibling(int row, int column, const GModelIndex& parent) const
|
|
{
|
|
if (!parent.is_valid())
|
|
return {};
|
|
int row_count = this->row_count(parent);
|
|
if (row < 0 || row > row_count)
|
|
return {};
|
|
return index(row, column, parent);
|
|
}
|