summaryrefslogtreecommitdiff
path: root/LibGUI/GModel.cpp
blob: ca8b3db6d7bc7bfd1a4f0137b54e1c778f476f4b (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
#include <LibGUI/GModel.h>
#include <LibGUI/GAbstractView.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_model_update)
        on_model_update(*this);
    for_each_view([] (auto& view) {
        view.did_update_model();
    });
}

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);
    if (m_activates_on_selection && is_valid(index))
        activate(index);
}