From f9b8a18fae316479033616354add908c3f2d27ca Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 14 Aug 2019 20:30:18 +0200 Subject: [PATCH] GJsonArrayModel: Add hook for customizing the GModel::Role::Custom data --- Libraries/LibGUI/GJsonArrayModel.cpp | 7 +++++++ Libraries/LibGUI/GJsonArrayModel.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/GJsonArrayModel.cpp b/Libraries/LibGUI/GJsonArrayModel.cpp index 52f329c324..d819518f92 100644 --- a/Libraries/LibGUI/GJsonArrayModel.cpp +++ b/Libraries/LibGUI/GJsonArrayModel.cpp @@ -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 {}; } diff --git a/Libraries/LibGUI/GJsonArrayModel.h b/Libraries/LibGUI/GJsonArrayModel.h index a5e9f14ceb..25780e6e1e 100644 --- a/Libraries/LibGUI/GJsonArrayModel.h +++ b/Libraries/LibGUI/GJsonArrayModel.h @@ -7,11 +7,12 @@ class GJsonArrayModel final : public GModel { public: struct FieldSpec { - FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function&& a_massage_for_display, Function&& a_massage_for_sort = {}) + FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function&& a_massage_for_display, Function&& a_massage_for_sort = {}, Function&& 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 massage_for_display; Function massage_for_sort; + Function massage_for_custom; }; static NonnullRefPtr create(const String& json_path, Vector&& fields)