mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
GJsonArrayModel: Add hook for customizing the GModel::Role::Custom data
This commit is contained in:
parent
1ac963b5c8
commit
f9b8a18fae
Notes:
sideshowbarker
2024-07-19 12:40:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f9b8a18fae3
2 changed files with 10 additions and 1 deletions
|
@ -46,6 +46,13 @@ GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const
|
|||
return field_spec.massage_for_sort(object);
|
||||
return data(index, Role::Display);
|
||||
}
|
||||
|
||||
if (role == GModel::Role::Custom) {
|
||||
if (field_spec.massage_for_custom)
|
||||
return field_spec.massage_for_custom(object);
|
||||
return {};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
class GJsonArrayModel final : public GModel {
|
||||
public:
|
||||
struct FieldSpec {
|
||||
FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<GVariant(const JsonObject&)>&& a_massage_for_display, Function<GVariant(const JsonObject&)>&& a_massage_for_sort = {})
|
||||
FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<GVariant(const JsonObject&)>&& a_massage_for_display, Function<GVariant(const JsonObject&)>&& a_massage_for_sort = {}, Function<GVariant(const JsonObject&)>&& a_massage_for_custom = {})
|
||||
: column_name(a_column_name)
|
||||
, text_alignment(a_text_alignment)
|
||||
, massage_for_display(move(a_massage_for_display))
|
||||
, massage_for_sort(move(a_massage_for_sort))
|
||||
, massage_for_custom(move(a_massage_for_custom))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -27,6 +28,7 @@ public:
|
|||
TextAlignment text_alignment;
|
||||
Function<GVariant(const JsonObject&)> massage_for_display;
|
||||
Function<GVariant(const JsonObject&)> massage_for_sort;
|
||||
Function<GVariant(const JsonObject&)> massage_for_custom;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields)
|
||||
|
|
Loading…
Add table
Reference in a new issue