mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:27:43 +00:00
GJsonArrayModel: Add hook for customizing the GModel::Role::Custom data
This commit is contained in:
parent
1ac963b5c8
commit
f9b8a18fae
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 field_spec.massage_for_sort(object);
|
||||||
return data(index, Role::Display);
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,12 @@
|
||||||
class GJsonArrayModel final : public GModel {
|
class GJsonArrayModel final : public GModel {
|
||||||
public:
|
public:
|
||||||
struct FieldSpec {
|
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)
|
: column_name(a_column_name)
|
||||||
, text_alignment(a_text_alignment)
|
, text_alignment(a_text_alignment)
|
||||||
, massage_for_display(move(a_massage_for_display))
|
, massage_for_display(move(a_massage_for_display))
|
||||||
, massage_for_sort(move(a_massage_for_sort))
|
, massage_for_sort(move(a_massage_for_sort))
|
||||||
|
, massage_for_custom(move(a_massage_for_custom))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ public:
|
||||||
TextAlignment text_alignment;
|
TextAlignment text_alignment;
|
||||||
Function<GVariant(const JsonObject&)> massage_for_display;
|
Function<GVariant(const JsonObject&)> massage_for_display;
|
||||||
Function<GVariant(const JsonObject&)> massage_for_sort;
|
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)
|
static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue