mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-30 16:28:48 +00:00
GJsonArrayModel: Add an optional "massage_for_display" fieldspec hook
This allows to you install a custom callback that can do anything with Role::Display data before it's returned by GJsonArrayModel::data().
This commit is contained in:
parent
0f0a528323
commit
078ce97c41
Notes:
sideshowbarker
2024-07-19 12:46:24 +09:00
Author: https://github.com/awesomekling
Commit: 078ce97c41
3 changed files with 46 additions and 24 deletions
|
@ -26,11 +26,14 @@ GModel::ColumnMetadata GJsonArrayModel::column_metadata(int column) const
|
|||
|
||||
GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const
|
||||
{
|
||||
auto& field_spec = m_fields[index.column()];
|
||||
auto& object = m_array.at(index.row()).as_object();
|
||||
|
||||
if (role == GModel::Role::Display) {
|
||||
auto& json_field_name = m_fields[index.column()].json_field_name;
|
||||
auto& json_field_name = field_spec.json_field_name;
|
||||
auto data = object.get(json_field_name);
|
||||
if (field_spec.massage_for_display)
|
||||
return field_spec.massage_for_display(data);
|
||||
if (data.is_int())
|
||||
return data.as_int();
|
||||
if (data.is_uint())
|
||||
|
@ -39,3 +42,12 @@ GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const
|
|||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void GJsonArrayModel::set_json_path(const String& json_path)
|
||||
{
|
||||
if (m_json_path == json_path)
|
||||
return;
|
||||
|
||||
m_json_path = json_path;
|
||||
update();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue