From 00ab8e0a149d4851f72c193c04a2c3ab61d89340 Mon Sep 17 00:00:00 2001 From: Brendan Kelly Date: Mon, 29 Jan 2024 11:15:15 -0500 Subject: [PATCH] Maps: Add massage_for_display for lat and long This prevents a crash when attempting to add a favorite or load favorites list in Maps application --- Userland/Applications/Maps/FavoritesPanel.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Maps/FavoritesPanel.cpp b/Userland/Applications/Maps/FavoritesPanel.cpp index 6bca950a34..465eced251 100644 --- a/Userland/Applications/Maps/FavoritesPanel.cpp +++ b/Userland/Applications/Maps/FavoritesPanel.cpp @@ -61,8 +61,12 @@ void FavoritesPanel::load_favorites() double longitude = object.get_double_with_precision_loss("longitude"sv).release_value(); return ByteString::formatted("{}\n{:.5}, {:.5}", name, latitude, longitude); }); - favorites_fields.empend("latitude", "Latitude"_string, Gfx::TextAlignment::CenterLeft); - favorites_fields.empend("longitude", "Longitude"_string, Gfx::TextAlignment::CenterLeft); + favorites_fields.empend("latitude", "Latitude"_string, Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) -> GUI::Variant { + return object.get_double_with_precision_loss("latitude"sv).release_value(); + }); + favorites_fields.empend("longitude", "Longitude"_string, Gfx::TextAlignment::CenterLeft, [](JsonObject const& object) -> GUI::Variant { + return object.get_double_with_precision_loss("longitude"sv).release_value(); + }); favorites_fields.empend("zoom", "Zoom"_string, Gfx::TextAlignment::CenterLeft); m_favorites_list->set_model(*GUI::JsonArrayModel::create(ByteString::formatted("{}/MapsFavorites.json", Core::StandardPaths::config_directory()), move(favorites_fields))); m_favorites_list->model()->invalidate(); @@ -136,11 +140,12 @@ void FavoritesPanel::favorites_changed() m_favorites_list->set_visible(model.row_count() > 0); Vector favorites; - for (int index = 0; index < model.row_count(); index++) + for (int index = 0; index < model.row_count(); index++) { favorites.append({ MUST(String::from_byte_string(model.index(index, 0).data().to_byte_string())), { model.index(index, 1).data().as_double(), model.index(index, 2).data().as_double() }, model.index(index, 3).data().to_i32() }); + } on_favorites_change(favorites); }