2019-02-28 12:57:09 +03:00
|
|
|
#include <LibGUI/GTableModel.h>
|
|
|
|
#include <LibGUI/GTableView.h>
|
|
|
|
|
|
|
|
GTableModel::GTableModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GTableModel::~GTableModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GTableModel::register_view(Badge<GTableView>, GTableView& view)
|
|
|
|
{
|
|
|
|
m_views.set(&view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GTableModel::unregister_view(Badge<GTableView>, GTableView& view)
|
|
|
|
{
|
|
|
|
m_views.remove(&view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GTableModel::for_each_view(Function<void(GTableView&)> callback)
|
|
|
|
{
|
|
|
|
for (auto* view : m_views)
|
|
|
|
callback(*view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GTableModel::did_update()
|
|
|
|
{
|
2019-03-09 15:33:52 +03:00
|
|
|
if (on_model_update)
|
|
|
|
on_model_update(*this);
|
2019-02-28 12:57:09 +03:00
|
|
|
for_each_view([] (GTableView& view) {
|
|
|
|
view.did_update_model();
|
|
|
|
});
|
|
|
|
}
|
2019-03-15 18:25:30 +03:00
|
|
|
|
|
|
|
void GTableModel::set_selected_index(const GModelIndex& index)
|
|
|
|
{
|
|
|
|
if (m_selected_index == index)
|
|
|
|
return;
|
|
|
|
m_selected_index = index;
|
|
|
|
if (on_selection_changed)
|
|
|
|
on_selection_changed(index);
|
|
|
|
if (m_activates_on_selection && is_valid(index))
|
|
|
|
activate(index);
|
|
|
|
}
|