diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-10 15:06:29 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-10 15:06:29 +0200 |
commit | afd25679bc4e72db304322289af0566bde0b60b0 (patch) | |
tree | eae26f3fdb93882e38e66b7d1838c11e77b58428 /Libraries | |
parent | a4548a150f339156c05455a11a66c6e8c8888e7c (diff) | |
download | serenity-afd25679bc4e72db304322289af0566bde0b60b0.zip |
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. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GJsonArrayModel.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/GJsonArrayModel.h | 13 |
2 files changed, 11 insertions, 4 deletions
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 <AK/JsonArray.h> +#include <AK/JsonObject.h> #include <LibGUI/GModel.h> 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<GVariant(const GVariant&)>&& a_massage_for_display = {}) + FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<GVariant(const JsonObject&)>&& 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<GVariant(const GVariant&)> massage_for_display; + Function<GVariant(const JsonObject&)> massage_for_display; }; static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields) |