blob: d1c4e94d35c12f6cb6bbba5b924d033f28a82cbd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#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);
}
|