From 93d04b9f8db389ad9c7a121c3dfb7c6602645004 Mon Sep 17 00:00:00 2001 From: asynts Date: Mon, 5 Oct 2020 18:16:10 +0200 Subject: [PATCH] LibGUI: Add formatter for ModelIndex. --- Libraries/LibGUI/ModelIndex.cpp | 14 ++++++++++++++ Libraries/LibGUI/ModelIndex.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/Libraries/LibGUI/ModelIndex.cpp b/Libraries/LibGUI/ModelIndex.cpp index 1c31d3f3bf..982969f0c3 100644 --- a/Libraries/LibGUI/ModelIndex.cpp +++ b/Libraries/LibGUI/ModelIndex.cpp @@ -47,3 +47,17 @@ const LogStream& operator<<(const LogStream& stream, const ModelIndex& value) } } + +namespace AK { + +void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::ModelIndex& value) +{ + Formatter formatter { *this }; + + if (value.internal_data()) + formatter.format(params, builder, String::formatted("ModelIndex({},{},{:p})", value.row(), value.column(), value.internal_data())); + else + formatter.format(params, builder, String::formatted("ModelIndex({},{})", value.row(), value.column())); +} + +} diff --git a/Libraries/LibGUI/ModelIndex.h b/Libraries/LibGUI/ModelIndex.h index 6c2c449f8f..222ea7f1b7 100644 --- a/Libraries/LibGUI/ModelIndex.h +++ b/Libraries/LibGUI/ModelIndex.h @@ -80,8 +80,15 @@ const LogStream& operator<<(const LogStream&, const ModelIndex&); } namespace AK { + +template<> +struct Formatter : Formatter { + void format(TypeErasedFormatParams&, FormatBuilder&, const GUI::ModelIndex&); +}; + template<> struct Traits : public GenericTraits { static unsigned hash(const GUI::ModelIndex& index) { return pair_int_hash(index.row(), index.column()); } }; + }