2019-03-23 02:04:31 +01:00
|
|
|
#include <LibGUI/GAbstractView.h>
|
2019-06-07 11:46:02 +02:00
|
|
|
#include <LibGUI/GModel.h>
|
2019-02-28 10:57:09 +01:00
|
|
|
|
2019-03-23 01:42:49 +01:00
|
|
|
GModel::GModel()
|
2019-02-28 10:57:09 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-23 01:42:49 +01:00
|
|
|
GModel::~GModel()
|
2019-02-28 10:57:09 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:04:31 +01:00
|
|
|
void GModel::register_view(Badge<GAbstractView>, GAbstractView& view)
|
2019-02-28 10:57:09 +01:00
|
|
|
{
|
|
|
|
m_views.set(&view);
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:04:31 +01:00
|
|
|
void GModel::unregister_view(Badge<GAbstractView>, GAbstractView& view)
|
2019-02-28 10:57:09 +01:00
|
|
|
{
|
|
|
|
m_views.remove(&view);
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:04:31 +01:00
|
|
|
void GModel::for_each_view(Function<void(GAbstractView&)> callback)
|
2019-02-28 10:57:09 +01:00
|
|
|
{
|
|
|
|
for (auto* view : m_views)
|
|
|
|
callback(*view);
|
|
|
|
}
|
|
|
|
|
2019-03-23 01:42:49 +01:00
|
|
|
void GModel::did_update()
|
2019-02-28 10:57:09 +01:00
|
|
|
{
|
2019-08-20 19:45:08 +02:00
|
|
|
if (on_update)
|
|
|
|
on_update();
|
2019-06-07 11:46:02 +02:00
|
|
|
for_each_view([](auto& view) {
|
2019-02-28 10:57:09 +01:00
|
|
|
view.did_update_model();
|
|
|
|
});
|
|
|
|
}
|
2019-03-15 16:25:30 +01:00
|
|
|
|
2019-08-18 10:14:53 +02:00
|
|
|
GModelIndex GModel::create_index(int row, int column, const void* data) const
|
2019-03-29 04:58:15 +01:00
|
|
|
{
|
2019-08-18 10:14:53 +02:00
|
|
|
return GModelIndex(*this, row, column, const_cast<void*>(data));
|
2019-03-29 04:58:15 +01:00
|
|
|
}
|
2019-03-29 19:48:15 +01:00
|
|
|
|
|
|
|
GModelIndex GModel::sibling(int row, int column, const GModelIndex& parent) const
|
|
|
|
{
|
|
|
|
if (!parent.is_valid())
|
2019-12-13 23:36:36 +01:00
|
|
|
return index(row, column, {});
|
2019-03-29 19:48:15 +01:00
|
|
|
int row_count = this->row_count(parent);
|
|
|
|
if (row < 0 || row > row_count)
|
2019-06-07 11:46:02 +02:00
|
|
|
return {};
|
2019-03-29 19:48:15 +01:00
|
|
|
return index(row, column, parent);
|
|
|
|
}
|