1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibGUI: Fix const-correctness issues

This commit is contained in:
Andreas Kling 2023-02-20 19:03:44 +01:00
parent bfe081caad
commit faa1a09042
44 changed files with 180 additions and 183 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
@ -1042,7 +1042,7 @@ Vector<Widget&> Widget::child_widgets() const
return widgets;
}
void Widget::set_palette(Palette const& palette)
void Widget::set_palette(Palette& palette)
{
m_palette = palette.impl();
update();
@ -1126,14 +1126,14 @@ Gfx::IntRect Widget::children_clip_rect() const
return rect();
}
void Widget::set_override_cursor(AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor)
void Widget::set_override_cursor(AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap const>> cursor)
{
auto const& are_cursors_the_same = [](AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> const& a, AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> const& b) {
if (a.has<Gfx::StandardCursor>() != b.has<Gfx::StandardCursor>())
auto const& are_cursors_the_same = [](auto const& a, auto const& b) {
if (a.template has<Gfx::StandardCursor>() != b.template has<Gfx::StandardCursor>())
return false;
if (a.has<Gfx::StandardCursor>())
return a.get<Gfx::StandardCursor>() == b.get<Gfx::StandardCursor>();
return a.get<NonnullRefPtr<Gfx::Bitmap>>().ptr() == b.get<NonnullRefPtr<Gfx::Bitmap>>().ptr();
if (a.template has<Gfx::StandardCursor>())
return a.template get<Gfx::StandardCursor>() == b.template get<Gfx::StandardCursor>();
return a.template get<NonnullRefPtr<Gfx::Bitmap const>>().ptr() == b.template get<NonnullRefPtr<Gfx::Bitmap const>>().ptr();
};
if (are_cursors_the_same(m_override_cursor, cursor))
@ -1159,19 +1159,19 @@ ErrorOr<void> Widget::load_from_gml(StringView gml_string, UnregisteredChildHand
return load_from_gml_ast(value, unregistered_child_handler);
}
ErrorOr<void> Widget::load_from_gml_ast(NonnullRefPtr<GUI::GML::Node> ast, UnregisteredChildHandler unregistered_child_handler)
ErrorOr<void> Widget::load_from_gml_ast(NonnullRefPtr<GUI::GML::Node const> ast, UnregisteredChildHandler unregistered_child_handler)
{
if (is<GUI::GML::GMLFile>(ast.ptr()))
return load_from_gml_ast(static_ptr_cast<GUI::GML::GMLFile>(ast)->main_class(), unregistered_child_handler);
return load_from_gml_ast(static_cast<GUI::GML::GMLFile const&>(*ast).main_class(), unregistered_child_handler);
VERIFY(is<GUI::GML::Object>(ast.ptr()));
auto object = static_ptr_cast<GUI::GML::Object>(ast);
auto const& object = static_cast<GUI::GML::Object const&>(*ast);
object->for_each_property([&](auto key, auto value) {
object.for_each_property([&](auto key, auto value) {
set_property(key, value);
});
auto layout = object->layout_object();
auto layout = object.layout_object();
if (!layout.is_null()) {
auto class_name = layout->name();
if (class_name.is_null()) {
@ -1198,8 +1198,8 @@ ErrorOr<void> Widget::load_from_gml_ast(NonnullRefPtr<GUI::GML::Node> ast, Unreg
auto& widget_class = *Core::ObjectClassRegistration::find("GUI::Widget"sv);
bool is_tab_widget = is<TabWidget>(*this);
TRY(object->try_for_each_child_object([&](auto child_data) -> ErrorOr<void> {
auto class_name = child_data->name();
TRY(object.try_for_each_child_object([&](auto const& child_data) -> ErrorOr<void> {
auto class_name = child_data.name();
// It is very questionable if this pseudo object should exist, but it works fine like this for now.
if (class_name == "GUI::Layout::Spacer") {