mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
GJsonArrayModel: Add hook to customize what comes out of GModel::Sort
Now you can provide a massage_for_sort hook in your FieldSpec. This allows you to implement arbitrary sorting rules for the data.
This commit is contained in:
parent
2c7b0b8893
commit
69ec08774b
2 changed files with 9 additions and 1 deletions
|
@ -40,6 +40,12 @@ GVariant GJsonArrayModel::data(const GModelIndex& index, Role role) const
|
||||||
return data.as_uint();
|
return data.as_uint();
|
||||||
return object.get(json_field_name).to_string();
|
return object.get(json_field_name).to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == GModel::Role::Sort) {
|
||||||
|
if (field_spec.massage_for_sort)
|
||||||
|
return field_spec.massage_for_sort(object);
|
||||||
|
return data(index, Role::Display);
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
class GJsonArrayModel final : public GModel {
|
class GJsonArrayModel final : public GModel {
|
||||||
public:
|
public:
|
||||||
struct FieldSpec {
|
struct FieldSpec {
|
||||||
FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<GVariant(const JsonObject&)>&& a_massage_for_display = {})
|
FieldSpec(const String& a_column_name, TextAlignment a_text_alignment, Function<GVariant(const JsonObject&)>&& a_massage_for_display, Function<GVariant(const JsonObject&)>&& a_massage_for_sort = {})
|
||||||
: column_name(a_column_name)
|
: column_name(a_column_name)
|
||||||
, text_alignment(a_text_alignment)
|
, text_alignment(a_text_alignment)
|
||||||
, massage_for_display(move(a_massage_for_display))
|
, massage_for_display(move(a_massage_for_display))
|
||||||
|
, massage_for_sort(move(a_massage_for_sort))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ public:
|
||||||
String column_name;
|
String column_name;
|
||||||
TextAlignment text_alignment;
|
TextAlignment text_alignment;
|
||||||
Function<GVariant(const JsonObject&)> massage_for_display;
|
Function<GVariant(const JsonObject&)> massage_for_display;
|
||||||
|
Function<GVariant(const JsonObject&)> massage_for_sort;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields)
|
static NonnullRefPtr<GJsonArrayModel> create(const String& json_path, Vector<FieldSpec>&& fields)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue