From afd25679bc4e72db304322289af0566bde0b60b0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 10 Aug 2019 15:06:29 +0200 Subject: GJsonArrayModel: Support fields that aren't tied to a single JSON value Change the custom data massaging callback to take a const JsonObject&. This will allow binding together data from multiple fields into one output in the model. :^) --- Libraries/LibGUI/GJsonArrayModel.cpp | 2 +- Libraries/LibGUI/GJsonArrayModel.h | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'Libraries') diff --git a/Libraries/LibGUI/GJsonArrayModel.cpp b/Libraries/LibGUI/GJsonArrayModel.cpp index be93510ddf..ea4845f58a 100644 --- a/Libraries/LibGUI/GJsonArrayModel.cpp +++ b/Libraries/LibGUI/GJsonArrayModel.cpp @@ -33,7 +33,7 @@ GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const 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); + return field_spec.massage_for_display(object); if (data.is_int()) return data.as_int(); if (data.is_uint()) diff --git a/Libraries/LibGUI/GJsonArrayModel.h b/Libraries/LibGUI/GJsonArrayModel.h index c46e74689a..21095fccf1 100644 --- a/Libraries/LibGUI/GJsonArrayModel.h +++ b/Libraries/LibGUI/GJsonArrayModel.h @@ -1,23 +1,30 @@ #pragma once #include +#include #include class GJsonArrayModel final : public GModel { public: struct FieldSpec { - FieldSpec(const String& a_json_field_name, const String& a_column_name, TextAlignment a_text_alignment, Function&& a_massage_for_display = {}) + FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function&& a_massage_for_display = {}) + : column_name(a_column_name) + , text_alignment(a_text_alignment) + , massage_for_display(move(a_massage_for_display)) + { + } + + FieldSpec(const String& a_json_field_name, const String& a_column_name, TextAlignment a_text_alignment) : json_field_name(a_json_field_name) , column_name(a_column_name) , text_alignment(a_text_alignment) - , massage_for_display(move(a_massage_for_display)) { } String json_field_name; String column_name; TextAlignment text_alignment; - Function massage_for_display; + Function massage_for_display; }; static NonnullRefPtr create(const String& json_path, Vector&& fields) -- cgit v1.2.3