1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:25:10 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2019-08-10 15:06:29 +02:00
parent a4548a150f
commit afd25679bc
3 changed files with 13 additions and 6 deletions

View file

@ -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)