mirror of
https://github.com/RGBCube/serenity
synced 2025-05-26 01:55:08 +00:00
GJsonArrayModel: Add an optional "massage_for_display" fieldspec hook
This allows to you install a custom callback that can do anything with Role::Display data before it's returned by GJsonArrayModel::data().
This commit is contained in:
parent
0f0a528323
commit
078ce97c41
3 changed files with 46 additions and 24 deletions
|
@ -6,9 +6,18 @@
|
|||
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 = {})
|
||||
: 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;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields)
|
||||
|
@ -25,6 +34,9 @@ public:
|
|||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override;
|
||||
|
||||
const String& json_path() const { return m_json_path; }
|
||||
void set_json_path(const String& json_path);
|
||||
|
||||
private:
|
||||
GJsonArrayModel(const String& json_path, Vector<FieldSpec>&& fields)
|
||||
: m_json_path(json_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue